﻿// ## 2023/05/11 # 江东新风 # 添加疑兵相关参数到setting_info ##
// ## 2023/02/06 # 铃 # 把所有的内政执行官.和内政收支的结构体全部独立出来,把之前的改动恢复原位##
// ## 2022/08/14 # 铃 # 新增内政执行官的结构体,后续考虑是不是单独出来更好 ##
// ## 2022/08/09 # 铃 # 修复了小二反馈的数组边界错误的bug ##
// ## 2022/04/16 # 江东新风 # for范围调整 ##
// ## 2022/02/14 # 江东新风 # 部分常量中文化 ##
// ## 2022/02/06 # 江东新风 # 部分信息未正确储存 ##
// ## 2022/02/04 # 江东新风 # 尝试修复列传变一样错误 ##
// ## 2021/11/22 # 江东新风 # 加入事件相关记录，修复bug ##
// ## 2021/10/29 # 江东新风 # 结构体存储调用方式改进 ##
// ## 2021/10/28 # 江东新风 # 单港关存活默认值 ##
// ## 2021/10/24 # 江东新风 # 部队伤兵参数 ##
// ## 2021/10/18 # 江东新风 # 事件 曹操南征参数 ##
// ## 2021/09/26 # 江东新风 # 在势力结构体添加协同请求相关参数,新人才选拔系统相关列传参数 ##
// ## 2021/03/21 # 江东新风 # 自动组队bug修复 ##
// ## 2021/03/20 # 江东新风 # 自动组队相关信息 ##
// ## 2021/03/07 # 江东新风 # 新增选拔人才相关参数 ##
// ## 2021/03/05 # 江东新风 # 为人才选拔加入列传信息记录 ##
// ## 2021/02/16 # 江东新风 # 修复默认战马武器异常bug ##
// ## 2021/02/07 # 江东新风 # bug修复 ##
// ## 2021/02/04 # 江东新风 # 武将结构体添加武器及马匹参数 ##
// ## 2021/01/29 # 江东新风 # 针对事件的结构体支持 ##
// ## 2021/01/23 # 江东新风 # 结构体设定内容增加，为金钱投资和请求军粮提供支持 ##
// ## 2021/01/22 # 江东新风 # 结构体相关设定，必须最早加载 ##


//如想在一个文件写，可以考虑多加几个namespace
namespace 结构体读取与储存
{
	/// KEY index 的类型是 (uint16),所以最高支持65535,已达上限， 测试无法扩增

	//通过key区分每个结构体类型，这样可以使每个元素都能分别达到65535的上限
	const uint KEY_EXDATA = pk::hash("EXdata");
	const uint KEY_据点 = pk::hash("据点结构体");
	const int KEY_索引_追加_据点起始 = 0;					// 索引追加建筑结构体 uint32数量为30个，据点共86个。总计2580，上限uint32数=65000/86=755

	const uint KEY_武将 = pk::hash("武将结构体");
	const int KEY_索引_追加_武将起始 = 0;					// 索引追加武将结构体 uint32数量为20个，武将共1100个。总计22000，上限uint32数=65000/1100=59

	const uint KEY_部队 = pk::hash("部队结构体");
	const int KEY_索引_追加_部队起始 = 0;					// 索引追加部队结构体 uint32数量为10个，部队共1000个。总计10000，上限uint32数=65000/1000=65

	const uint KEY_势力 = pk::hash("势力结构体");
	const int KEY_索引_追加_势力起始 = 0;					// 索引追加势力结构体 uint32数量为20个，势力共46个。总计920，上限uint32数=65000/46=1413

	const uint KEY_地名 = pk::hash("地名结构体");
	const int KEY_索引_追加_地名起始 = 0;					// 索引追加地名结构体 uint32数量为20个，地名共221个。总计4420，上限uint32数=65000/221=294

	const uint KEY_其他 = pk::hash("其他结构体");
	const uint KEY_组队 = pk::hash("组队结构体");
	const uint KEY_设定 = pk::hash("设定结构体");
	const int KEY_索引_追加_组队起始 = 0;					// 索引追加自动组队结构体 uint32数量为3个，记录数共300个。总计900
	const int KEY_索引_追加_设定起始 = 10000;					// 索引追加游戏基础设定结构体 uint32数量为135个

	const uint KEY_宝物 = pk::hash("宝物附加存档");
	const int latest_support_version = 240115;

	//暂时只考虑附加宝物数据，但位置留了内置宝物
	const int 起始字节_宝物 = 20;//当前每个结构体占57字节,总计可用70字节
	const int 起始字节_武将 = 8 + 起始字节_宝物 + 预留字节_宝物 * 扩展宝物_末;//当前每个结构体占56字节,总计可用120字节
	const int 起始字节_据点 = 8 + 起始字节_武将 + 预留字节_武将 * 武将_末;//当前每个结构体占265字节,总计可用500字节
	const int 起始字节_部队 = 8 + 起始字节_据点 + 预留字节_据点 * 据点_末;//当前每个结构体占84字节,总计可用30字节
	const int 起始字节_势力 = 8 + 起始字节_部队 + 预留字节_部队 * 部队_末;//当前每个结构体占59字节,总计可用120字节
	const int 起始字节_地名 = 8 + 起始字节_势力 + 预留字节_势力 * 势力_末;//当前每个结构体占68字节,总计可用100字节
	const int 起始字节_设定 = 8 + 起始字节_地名 + 预留字节_地名 * 300;//当前每个结构体占154字节,总计可用300字节---此处预留空间大点，省得不够用？
	const int 起始字节_组队 = 8 + 起始字节_设定 + 预留字节_设定 * 设定_末;//当前每个结构体占10字节,总计可用20字节

	const array<string> EXdata_type_name = { "武将", "据点", "部队", "势力", "地名", "设定", "组队" };

	const array<string> EXdata_error_desc = { "hash不一致", "预留字节数不一致" };
	//武将id*3 16*3+兵种8*2 + 频次16
	//使用3个unit32存，给100个位置，那就是300
	//是否有必要加入玩家自定义参数的储存--如果加入，那kre中的更改将失效，直到重开游戏或游戏中改设定
	array<string> temp_list = { pk::encode("农民兵"), pk::encode("突袭者"), pk::encode("府兵"), pk::encode("雇佣兵"), pk::encode("贾诩小队") };


	class Main
	{
		pk::c_bool trace_ = pk::c_bool(false);
		Main()
		{
			//读档早于剧本初始化
			pk::bind2(102, pk::trigger102_t(剧本初始化_结构体_信息读取), 999);
			pk::bind(105, pk::trigger105_t(儲存_结构体_信息储存));
			pk::bind(106, pk::trigger106_t(load_game));

			pk::bind(111, pk::trigger111_t(onTurnStart));
			pk::bind(107, pk::trigger107_t(onNewDay));

			//pk::bind(260, pk::trigger260_t(IMGUI_test));
			pk::bind(261, pk::trigger261_t(IMGUI_test2));

			//相关的结构体信息初始化
			pk::bind(151, pk::trigger151_t(onPersonDied));
			pk::bind(152, pk::trigger152_t(onPersonChangeForce));

			pk::bind2(171, pk::trigger171_t(onUnitRemove), 8);
			pk::bind2(175, pk::trigger175_t(onUnitDestory), 8);

		}

		void IMGUI_test()
		{
			ImGui::Checkbox("调试模式", trace_);

			//文件内测试的写法
			if (trace_.v) pk::trace("输出测试内容");
		}

		void IMGUI_test2()
		{
			if (ImGui::BeginTabItem("person_ex"))
			{
				imgui_person_ex();
				ImGui::EndTabItem();
			}
			if (ImGui::BeginTabItem("base_ex"))
			{
				imgui_base_ex();
				ImGui::EndTabItem();
			}
			if (ImGui::BeginTabItem("baseIA_ex"))
			{
				imgui_baseIA_ex();
				ImGui::EndTabItem();
			}
			if (ImGui::BeginTabItem("talent_info"))
			{
				imgui_talent_ex();
				ImGui::EndTabItem();
			}
			if (ImGui::BeginTabItem("spec_ex"))
			{
				imgui_spec_ex();
				ImGui::EndTabItem();
			}
			if (ImGui::BeginTabItem("alliance_ex"))
			{
				imgui_alliance_ex();
				ImGui::EndTabItem();
			}
		}

		void imgui_person_ex()
		{
			if (ImGui::BeginTable("##person_ex", 33, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
			{
				ImGui::TableSetupScrollFreeze(1, 1);
				ImGui::TableSetupColumn("id");
				ImGui::TableSetupColumn("统率(浮动)");
				ImGui::TableSetupColumn("武力(浮动)");
				ImGui::TableSetupColumn("智力(浮动)");
				ImGui::TableSetupColumn("政治(浮动)");
				ImGui::TableSetupColumn("魅力(浮动)");

				ImGui::TableSetupColumn("马皮肤");
				ImGui::TableSetupColumn("武器皮肤");

				ImGui::TableSetupColumn("career");
				ImGui::TableSetupColumn("武将类型");
				ImGui::TableSetupColumn("人才类型");
				ImGui::TableSetupColumn("提拔原因");
				ImGui::TableSetupColumn("发现者");
				ImGui::TableSetupColumn("初始势力");

				ImGui::TableSetupColumn("appeared_city");
				ImGui::TableSetupColumn("杀敌数");
				ImGui::TableSetupColumn("部队杀敌数");
				ImGui::TableSetupColumn("封地");
				ImGui::TableSetupColumn("select_history_person_id");
				ImGui::TableSetupColumn("征兵经验");

				ImGui::TableSetupColumn("训练经验");
				ImGui::TableSetupColumn("巡查经验");
				ImGui::TableSetupColumn("生产经验");
				ImGui::TableSetupColumn("攻具经验");
				ImGui::TableSetupColumn("舰船经验");
				ImGui::TableSetupColumn("筑城经验");
				ImGui::TableSetupColumn("产马经验");

				ImGui::TableSetupColumn("自动内政据点");
				ImGui::TableSetupColumn("自动内政项目");
				ImGui::TableSetupColumn("击破部队数");
				ImGui::TableSetupColumn("士兵伤害数");
				ImGui::TableSetupColumn("被击溃总次数");
				ImGui::TableSetupColumn("被部队溃灭次数");

				ImGui::TableHeadersRow();

				for (int i = 0; i < 武将_末; i++)
				{

					auto person = pk::get_person(i);
					if (pk::is_alive(person))
					{
						auto person_t = @person_ex[i];//
						ImGui::PushID(i);
						ImGui::TableNextRow();

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}{}", i, pk::decode(pk::get_name(person))));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.float_command));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.float_strength));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.float_wisdom));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.float_politic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.float_charm));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.horse_id));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.weapon_id));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.career));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.person_type));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.talent_type));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.appeared_reason));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.discovered_by));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.init_force));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.appeared_city));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.kill_num));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.unit_kill_num));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.spec_id));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.select_history_person_id));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.recruit_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.drill_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.inspection_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.weapon_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.siege_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.ship_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.build_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.horse_exp));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.auto_affairs_base));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.auto_affairs_role));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.kill_unit));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.troops_damage));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.kill_destroyed));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", person_t.kill_unit_destroyed));

						ImGui::PopID();

					}

				}

				ImGui::EndTable();
			}
		}

		void imgui_base_ex()
		{

			if (ImGui::BeginTable("##base_ex", 44, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
			{
				ImGui::TableSetupScrollFreeze(1, 1);
				ImGui::TableSetupColumn("id");
				ImGui::TableSetupColumn("人口");
				ImGui::TableSetupColumn("兵役人口");
				ImGui::TableSetupColumn("预备役");
				ImGui::TableSetupColumn("伤兵");
				ImGui::TableSetupColumn("回归计时");

				ImGui::TableSetupColumn("待返回人口");
				ImGui::TableSetupColumn("巡查许可");
				ImGui::TableSetupColumn("训练许可");
				ImGui::TableSetupColumn("征兵许可");
				ImGui::TableSetupColumn("褒奖许可");
				ImGui::TableSetupColumn("运输许可");

				ImGui::TableSetupColumn("生产许可");
				ImGui::TableSetupColumn("征兵执行官");
				ImGui::TableSetupColumn("巡查执行官");
				ImGui::TableSetupColumn("训练执行官");
				ImGui::TableSetupColumn("生产执行官");

				ImGui::TableSetupColumn("自动化顺序");
				ImGui::TableSetupColumn("巡察治安");
				ImGui::TableSetupColumn("征兵兵粮比");
				ImGui::TableSetupColumn("征兵治安");
				ImGui::TableSetupColumn("征兵金");
				ImGui::TableSetupColumn("褒奖标准");

				ImGui::TableSetupColumn("港关治安");
				ImGui::TableSetupColumn("防流言计数");
				ImGui::TableSetupColumn("被挑衅cd");
				ImGui::TableSetupColumn("附加金收入");
				ImGui::TableSetupColumn("附加粮收入");
				ImGui::TableSetupColumn("据点金收入");

				ImGui::TableSetupColumn("据点粮收入");
				ImGui::TableSetupColumn("城市级别");

				ImGui::TableSetupColumn("征兵完成");
				ImGui::TableSetupColumn("巡查完成");
				ImGui::TableSetupColumn("紧急动员完成");
				ImGui::TableSetupColumn("募兵完成");

				ImGui::TableSetupColumn("据点扰乱完成");
				ImGui::TableSetupColumn("据点伪报完成");
				ImGui::TableSetupColumn("据点火计完成");
				ImGui::TableSetupColumn("据点攻心完成");
				ImGui::TableSetupColumn("据点奇袭完成");
				ImGui::TableSetupColumn("据点援军完成");
				ImGui::TableSetupColumn("讨价还价完成");
				ImGui::TableSetupColumn("兵装买卖完成");
				ImGui::TableSetupColumn("可召唤农民兵");

				ImGui::TableHeadersRow();

				for (int i = 0; i < 据点_末; i++)
				{

					auto building = pk::get_building(i);
					if (pk::is_alive(building))
					{
						auto base_t = ch::get_base_p(i);
						ImGui::PushID(i);
						ImGui::TableNextRow();

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}{}", i, pk::decode(pk::get_name(building))));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.population));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.mil_pop_all));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.mil_pop_av));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.wounded));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.return_timer));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.return_pop));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.can_inspections));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.can_drill));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.can_recruit));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.can_reward));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.can_transport));

						string s = "";
						for (uint j = 0; j < base_t.can_produce.length; j++)
							s += pk::format("{}", base_t.can_produce[j]);
						ImGui::TableNextColumn();
						ImGui::Text(s);

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.recruit_person));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.inspections_person));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.drill_person));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.produce_person));


						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.auto_sequence));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.inspections_std));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.drill_std));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.recruit_std_foodtroop));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.recruit_std_porder));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.recruit_std_gold));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.reward_std));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.public_order));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.anti_rumor));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.revenue_bonus));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.harvest_bonus));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.base_revenue));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.base_harvest));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.city_level));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.recruit_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.inspections_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.mobilize_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.enlist_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.perturb_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.misinform_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.fire_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.beguile_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.raid_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.reinforce_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.bargaining_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.weapon_merchant_done));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.farmer_count));


						ImGui::PopID();

					}

				}

				ImGui::EndTable();
			}
		}

		void imgui_baseIA_ex()
		{

			if (ImGui::BeginTable("##base_ex", 39, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
			{
				ImGui::TableSetupScrollFreeze(1, 1);

				ImGui::TableSetupColumn("id");
				ImGui::TableSetupColumn("征兵开支");
				ImGui::TableSetupColumn("巡查开支");
				ImGui::TableSetupColumn("训练开支");
				ImGui::TableSetupColumn("兵装开支");
				ImGui::TableSetupColumn("马开支");
				ImGui::TableSetupColumn("攻具开支");
				ImGui::TableSetupColumn("船开支");
				ImGui::TableSetupColumn("筑城开支");

				ImGui::TableSetupColumn("征兵执行官");
				ImGui::TableSetupColumn("巡查执行官");
				ImGui::TableSetupColumn("训练执行官");
				ImGui::TableSetupColumn("兵装执行官");
				ImGui::TableSetupColumn("马执行官");
				ImGui::TableSetupColumn("攻具执行官");
				ImGui::TableSetupColumn("造船执行官");

				ImGui::TableSetupColumn("征兵增量");
				ImGui::TableSetupColumn("巡查增量");
				ImGui::TableSetupColumn("训练增量");
				ImGui::TableSetupColumn("枪增量");
				ImGui::TableSetupColumn("戟增量");
				ImGui::TableSetupColumn("弩增量");
				ImGui::TableSetupColumn("马增量");
				ImGui::TableSetupColumn("井栏增量");
				ImGui::TableSetupColumn("冲车增量");
				ImGui::TableSetupColumn("船增量");
				ImGui::TableSetupColumn("筑城增量");

				ImGui::TableSetupColumn("据点下一旬收入");
				ImGui::TableSetupColumn("兵装维护费");
				ImGui::TableSetupColumn("军饷");
				ImGui::TableSetupColumn("征兵方针");
				ImGui::TableSetupColumn("征兵方针开支");
				ImGui::TableSetupColumn("井栏量");
				ImGui::TableSetupColumn("冲车量");
				ImGui::TableSetupColumn("舰船量");

				ImGui::TableSetupColumn("兵装选择");
				ImGui::TableSetupColumn("攻具选择");
				ImGui::TableSetupColumn("额外城防");

				ImGui::TableHeadersRow();

				for (int i = 0; i < 据点_末; i++)
				{

					auto building = pk::get_building(i);
					if (pk::is_alive(building))
					{
						auto base_t = ch::get_baseIA(i);
						ImGui::PushID(i);
						ImGui::TableNextRow();

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}{}{}", i, pk::decode(pk::get_name(building)), base_t.building_id));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.troops_effic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.porder_effic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.train_effic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.weapon_effic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.horse_effic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.punch_effic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.boat_effic));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.repair_effic));


						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", ch::get_person_name(base_t.recruit_person,true)));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", ch::get_person_name(base_t.inspections_person, true)));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", ch::get_person_name(base_t.drill_person, true)));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", ch::get_person_name(base_t.weapon_person, true)));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", ch::get_person_name(base_t.horse_person, true)));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", ch::get_person_name(base_t.punch_person, true)));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", ch::get_person_name(base_t.boat_person, true)));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.troops_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.porder_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.train_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.spear_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.halberd_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.bow_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.horse_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.well_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.punch_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.boat_gain));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.repair_gain));


						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.building_revenue));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.weapon_expense));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.troops_expense));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.building_policy));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.policy_expense));


						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.well));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.punch));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.boat));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.weapon_choose));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.arms_choose));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", base_t.city_defense));


						ImGui::PopID();

					}

				}

				ImGui::EndTable();
			}
		}

		void imgui_spec_ex()
		{

			if (ImGui::BeginTable("##spec_ex", 14, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
			{

				ImGui::TableSetupScrollFreeze(1, 1);
				ImGui::TableSetupColumn("id");
				ImGui::TableSetupColumn("武将");
				ImGui::TableSetupColumn("建筑id");
				ImGui::TableSetupColumn("金");
				ImGui::TableSetupColumn("粮");
				ImGui::TableSetupColumn("兵力");
				ImGui::TableSetupColumn("人口");

				ImGui::TableHeadersRow();

				for (int i = 0; i < ch::get_spec_end(); i++)
				{
					auto spec_t = @special_ex[i];//
					ImGui::PushID(i);
					ImGui::TableNextRow();

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", i));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", pk::decode(ch::get_spec_person_name(i))));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", spec_t.building_id));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", spec_t.gold));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", spec_t.food));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", spec_t.troops));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", spec_t.population));
				}

				ImGui::EndTable();
			}
		}

		void imgui_talent_ex()
		{

			if (ImGui::BeginTable("##talent_ex", 14, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
			{
				ImGui::TableSetupScrollFreeze(1, 1);
				ImGui::TableSetupColumn("势力");
				ImGui::TableSetupColumn("人才id");
				ImGui::TableSetupColumn("发现者");
				ImGui::TableSetupColumn("老师");
				ImGui::TableSetupColumn("最大能力");
				ImGui::TableSetupColumn("初始能力");

				ImGui::TableSetupColumn("状态");
				ImGui::TableSetupColumn("剩余时间");
				ImGui::TableSetupColumn("是否延长");
				ImGui::TableSetupColumn("是否外出");
				ImGui::TableSetupColumn("训练事件");
				ImGui::TableSetupColumn("近期特殊事件");

				ImGui::TableSetupColumn("教学方法");
				ImGui::TableSetupColumn("外出时间");

				ImGui::TableHeadersRow();


				for (int i = 0; i < 势力_末; i++)
				{

					auto force = pk::get_force(i);
					if (pk::is_alive(force))
					{
						auto force_t = @force_ex[i];//
						ImGui::PushID(i);
						ImGui::TableNextRow();

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}{}", i, pk::decode(pk::get_name(force))));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.talent_id));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.discovered_by));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.teacher_id));

						string s = "";
						for (uint j = 0; j < 武将能力_末; j++)
							s += pk::format("{}|", force_t.max_stat[j]);
						ImGui::TableNextColumn();
						ImGui::Text(s);

						s = "";
						for (uint j = 0; j < 武将能力_末; j++)
							s += pk::format("{}|", force_t.init_stat[j]);
						ImGui::TableNextColumn();
						ImGui::Text(s);

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.talent_status));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.remained_time));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.time_extended));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.is_out));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.train_event));

						s = "";
						for (uint j = 0; j < 3; j++)
							s += pk::format("{}|", force_t.recent_special_event[j]);
						ImGui::TableNextColumn();
						ImGui::Text(s);

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.teaching_method));

						ImGui::TableNextColumn();
						ImGui::Text(pk::format("{}", force_t.out_time));


					}

				}

				ImGui::EndTable();
			}
		}


		void imgui_alliance_ex()
		{

			if (ImGui::BeginTable("##alliance_ex", 14, ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
			{

				ImGui::TableSetupScrollFreeze(1, 1);
				ImGui::TableSetupColumn("id");
				ImGui::TableSetupColumn("目标");
				ImGui::TableSetupColumn("盟主");
				ImGui::TableSetupColumn("目标据点");
				ImGui::TableSetupColumn("成员");
				ImGui::TableSetupColumn("剩余时间");

				ImGui::TableHeadersRow();


				for (int i = 0; i < 4; i++)
				{
					ImGui::PushID(i);
					ImGui::TableNextRow();

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", i));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", ch::get_force_name(setting_ex[0].alliance_target_id[i],true)));

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", ch::get_force_name(setting_ex[0].alliance_leader_id[i], true))); 

					string s = "";
					for (uint j = 0; j < 6; j++)
						s += pk::format("{}|", setting_ex[0].alliance_target_base[i][j]);
					ImGui::TableNextColumn();
					ImGui::Text(s);

					s = "";
					for (uint j = 0; j < 5; j++)
						s += pk::format("{}|", ch::get_force_name(setting_ex[0].alliance_member_id[i][j], true)); 
					ImGui::TableNextColumn();
					ImGui::Text(s);

					ImGui::TableNextColumn();
					ImGui::Text(pk::format("{}", setting_ex[0].alliance_remain_time[i]));


				}

				ImGui::EndTable();
			}
		}

		void 儲存_结构体_信息储存(int file_id, pk::s11writer@ w) //儲存
		{
			//pk::trace("start serialize");
			exdata_serialize(w);
			//pk::trace("end serialize");
		}

		void load_game(int file_id, pk::s11reader@ r)
		{
			//pk::trace("start load_game");
			int error = exdata_deserialize(r);
			if (error != 0)
			{
				//存档版本不支持
				string error_str = error == 1 ? "当前版本存档不支持" : "存档hash校验不通过";
				pk::message_box(pk::encode(pk::format("{}，可能出现大量错误，建议重新开档游戏！", error_str)));
			}
			//pk::trace("end load");

			//读档后的一些处理
			for (int i = 0; i < 武将_末; i++)
			{
				if (person_ex[i].weapon_id != 255)
					pk::set_person_weapon(i, person_ex[i].weapon_id);
				if (person_ex[i].horse_id != 255)
					pk::set_person_horse(i, person_ex[i].horse_id);
			}
			pk::set_auto_affairs(ch::get_set_p(0).get_mod_set(自动内政扩展_开关));
			set_city_spec_relate();
			set_base_spec_relate();
		}

		void 剧本初始化_结构体_信息读取()
		{
			//pk::trace("start load");

			//重新开始游戏时，初始化数据
			if (!pk::get_scenario().loaded) init_EXdata();//游戏开始前初始化数据，读档前也先初始化

			if (pk::get_scenario().loaded)
			{
				if (pk::get_player_count() == 0) pk::get_scenario().is_initializing = 0;//修复自动存档读档后，turn start trigger失效的问题，不确定是否会影响其他
			}

			set_city_spec_relate();
			set_base_spec_relate();
		}

		void exdata_serialize(pk::s11writer@ w)
		{
			//pk2的core的文件头包含了hash值，文件大小，以及根据数据，文件大小和hash值生成的校验hash值

			auto start_pos = w.getPos();

			write_header(w);
			if (start_pos + 起始字节_宝物 != w.getPos()) pk::trace(pk::format("起始字节_宝物异常:{}>{}", start_pos + 起始字节_宝物, w.getPos()));//w.setPos(start_pos + 起始字节_宝物);
			w.writeUInt32(KEY_宝物);
			w.writeInt32(预留字节_宝物);
			for (int i = 0; i < 扩展宝物_末; i++)
			{
				item_serialize(w, i);
			}

			if (start_pos + 起始字节_武将 != w.getPos())pk::trace(pk::format("起始字节_武将异常:{}>{}", start_pos + 起始字节_武将, w.getPos()));//w.setPos(start_pos + 起始字节_武将);
			w.writeUInt32(KEY_武将);
			w.writeInt32(预留字节_武将);
			for (int i = 0; i < 武将_末; i++)
			{
				person_ex[i].serialize(w);
			}
			//pk::trace("person_end pos:" + w.getPos());

			if (start_pos + 起始字节_据点 != w.getPos()) pk::trace("起始字节_据点异常");//w.setPos(start_pos + 起始字节_据点);
			w.writeUInt32(KEY_据点);
			w.writeInt32(预留字节_据点);
			for (int i = 0; i < 据点_末; i++)
			{
				base_ex[i].serialize(w);
			}
			//pk::trace("base_end pos:" + w.getPos());

			if (start_pos + 起始字节_部队 != w.getPos()) pk::trace("起始字节_部队异常");//w.setPos(start_pos + 起始字节_部队);
			w.writeUInt32(KEY_部队);
			w.writeInt32(预留字节_部队);
			for (int i = 0; i < 部队_末; i++)
			{
				unit_ex[i].serialize(w);
			}
			//pk::trace("unit_end pos:" + w.getPos());

			if (start_pos + 起始字节_势力 != w.getPos()) pk::trace("起始字节_势力异常");//w.setPos(start_pos + 起始字节_势力);
			w.writeUInt32(KEY_势力);
			w.writeInt32(预留字节_势力);
			for (int i = 0; i < 势力_末; i++)
			{
				force_ex[i].serialize(w);
			}
			//pk::trace("force_end pos:" + w.getPos());

			if (start_pos + 起始字节_地名 != w.getPos()) pk::trace("起始字节_地名异常");//w.setPos(start_pos + 起始字节_地名);
			w.writeUInt32(KEY_地名);
			w.writeInt32(预留字节_地名);
			for (int i = 0; i < ch::get_spec_end(); i++)
			{
				special_ex[i].serialize(w);
			}
			//地名特殊的占位措施
			for (int i = ch::get_spec_end(); i < 300; i++)
			{
				special_ex[0].serialize(w);
			}
			//pk::trace("spec_end pos:" + w.getPos());

			if (start_pos + 起始字节_设定 != w.getPos()) pk::trace("起始字节_设定异常");//w.setPos(start_pos + 起始字节_设定);
			w.writeUInt32(KEY_设定);
			w.writeInt32(预留字节_设定);
			for (int i = 0; i < 设定_末; i++)
			{
				setting_ex[i].serialize(w);
			}
			//pk::trace("setting_end pos:" + w.getPos());

			if (start_pos + 起始字节_组队 != w.getPos()) pk::trace("起始字节_组队异常");//w.setPos(start_pos + 起始字节_组队);
			w.writeUInt32(KEY_组队);
			w.writeInt32(预留字节_组队);
			for (int i = 0; i < 组队数_末; i++)
			{
				autoarmy_ex[i].serialize(w);
			}
		}

		int exdata_deserialize(pk::s11reader@ r)
		{
			init_EXdata();//读档前也先初始化
			auto start_pos = r.getPos();

			int error = check_header(r);

			r.setPos(start_pos + 起始字节_宝物);
			if (r.readUInt32() != KEY_宝物) error_info(EXdate_item, EXdate_error_hash);
			if (r.readInt32() != 预留字节_宝物) error_info(EXdate_item, EXdate_error_remain_byte);
			for (int i = 0; i < 扩展宝物_末; i++)
			{
				item_deserialize(r, i);
			}

			r.setPos(start_pos + 起始字节_武将);
			if (r.readUInt32() != KEY_武将) error_info(EXdate_person, EXdate_error_hash);
			if (r.readInt32() != 预留字节_武将) error_info(EXdate_person, EXdate_error_remain_byte);
			for (int i = 0; i < 武将_末; i++)
			{
				person_ex[i].deserialize(r, i);
			}

			r.setPos(start_pos + 起始字节_据点);
			if (r.readUInt32() != KEY_据点) error_info(EXdate_base, EXdate_error_hash);
			if (r.readInt32() != 预留字节_据点) error_info(EXdate_base, EXdate_error_remain_byte);
			for (int i = 0; i < 据点_末; i++)
			{
				base_ex[i].deserialize(r, i);
			}

			r.setPos(start_pos + 起始字节_部队);
			if (r.readUInt32() != KEY_部队) error_info(EXdate_unit, EXdate_error_hash);
			if (r.readInt32() != 预留字节_部队) error_info(EXdate_unit, EXdate_error_remain_byte);
			for (int i = 0; i < 部队_末; i++)
			{
				unit_ex[i].deserialize(r, i);
			}

			r.setPos(start_pos + 起始字节_势力);
			if (r.readUInt32() != KEY_势力) error_info(EXdate_force, EXdate_error_hash);
			if (r.readInt32() != 预留字节_势力) error_info(EXdate_force, EXdate_error_remain_byte);
			for (int i = 0; i < 势力_末; i++)
			{
				force_ex[i].deserialize(r, i);
			}

			r.setPos(start_pos + 起始字节_地名);
			if (r.readUInt32() != KEY_地名) error_info(EXdate_spec, EXdate_error_hash);
			if (r.readInt32() != 预留字节_地名) error_info(EXdate_spec, EXdate_error_remain_byte);
			for (int i = 0; i < ch::get_spec_end(); i++)
			{
				special_ex[i].deserialize(r, i);
			}

			r.setPos(start_pos + 起始字节_设定);
			if (r.readUInt32() != KEY_设定) error_info(EXdate_setting, EXdate_error_hash);
			if (r.readInt32() != 预留字节_设定) error_info(EXdate_setting, EXdate_error_remain_byte);
			for (int i = 0; i < 设定_末; i++)
			{
				setting_ex[i].deserialize(r, i);
			}

			r.setPos(start_pos + 起始字节_组队);
			if (r.readUInt32() != KEY_组队) error_info(EXdate_autoarmy, EXdate_error_hash);
			if (r.readInt32() != 预留字节_组队) error_info(EXdate_autoarmy, EXdate_error_remain_byte);
			for (int i = 0; i < 组队数_末; i++)
			{
				autoarmy_ex[i].deserialize(r, i);
			}
			return error;
		}

		void error_info(int date_type, int error_type)
		{
			string type_name = EXdata_type_name[date_type];
			string error_desc = EXdata_error_desc[error_type];
			pk::error(pk::format("{} {}，{}数据可能错误", type_name, error_desc, type_name));
		}

		string get_exdata_path(int file_id)
		{
			string str = file_id > 9 ? '' : '0';
			string path = '../pk2.2/Koei/San11/SaveData/' + 'Save0' + str + file_id + '.exsav';
			return path;
		}

		void write_header(pk::s11writer@ w)
		{
			int pre_pos = w.getPos();
			//先写文件头信息
			uint16 major = 2;
			uint8 minor = 7;
			uint8 patch = 5;
			int version = pk::get_mod_date();
			uint hash = KEY_EXDATA;

			//共 2+1+1+4+4 = 12;
			w.writeUInt16(major);
			w.writeUInt8(minor);
			w.writeUInt8(patch);
			w.writeInt32(version);
			w.writeUInt32(hash);
			int after_pos = w.getPos();
			ch::write_multibyte(w, 预留字节_文件头 - (after_pos - pre_pos));//
		}

		int check_header(pk::s11reader@ r)
		{
			int pre_pos = r.getPos();
			uint16 major = r.readUInt16();
			uint8 minor = r.readUInt8();
			uint8 patch = r.readUInt8();
			int version = r.readInt32();
			uint hash = r.readUInt32();

			int after_pos = r.getPos();
			ch::read_multibyte(r, 预留字节_文件头 - (after_pos - pre_pos));//

			if (version < latest_support_version) return 1;
			if (hash != KEY_EXDATA) return 2;
			return 0;
		}

		void item_serialize(pk::s11writer@ w, int id)
		{
			auto item = pk::get_item(id);
			//write时用
			int pre_pos = w.getPos();

			w.writeString(item.name, 13);
			w.writeString(item.name_read, 37);
			w.writeInt8(item.type);
			w.writeUInt8(item.value);
			w.writeInt8(item.face);
			w.writeInt16(item.owner);
			w.writeInt8(item.location);
			w.writeInt8(item.status);
			int after_pos = w.getPos();
			//占位,加入数据后，此处需减去对应字节数
			ch::write_multibyte(w, 预留字节_宝物 - (after_pos - pre_pos));//w.movePos(预留字节_宝物 - (after_pos - pre_pos));

		}

		void item_deserialize(pk::s11reader@ r, int id)
		{
			auto item = pk::get_item(id);
			int pre_pos = r.getPos();
			item.name = r.readString(13);
			item.name_read = r.readString(37);
			item.type = r.readInt8();
			item.value = r.readUInt8();
			item.face = r.readInt8();
			item.owner = r.readInt16();
			item.location = r.readInt8();
			item.status = r.readInt8();
			int after_pos = r.getPos();
			//占位,加入数据后，此处需减去对应字节数
			ch::read_multibyte(r, 预留字节_宝物 - (after_pos - pre_pos));//r.movePos(预留字节_宝物 - (after_pos - pre_pos));
			//int remain = after_pos - pre_pos;
			//for (int i = 0; i < remain / 4; ++i)
			//	f.readUInt32();
			//for (int i = 0; i < remain % 4; ++i)
			//	f.readUInt8();
		}

		void init_EXdata()
		{
			for (int i = 0; i < 据点_末; ++i)
			{
				base_ex[i].init();
			}

			for (int i = 0; i < 武将_末; ++i)
			{
				person_ex[i].init();
			}

			for (int i = 0; i < 部队_末; i++)
			{
				unit_ex[i].init();
			}

			for (int i = 0; i < 势力_末; ++i)
			{
				force_ex[i].init();
			}

			for (int i = 0; i < 地名_末; ++i)
			{
				special_ex[i].init();
			}

			for (int i = 0; i < 设定_末; ++i)
			{
				setting_ex[i].init();
			}

			for (int i = 0; i < 组队数_末; ++i)
			{
				autoarmy_ex[i].init();
			}
		}

		void set_city_spec_relate()
		{
			array<array<int>> city_spec_temp(城市_末, array<int>(最大城市县城数, int(-1)));//初始清空

			for (int i = 0; i < 地名_末; i++)
			{
				int city_id = pk::get_city_id(ch::get_spec_pos(i));
				for (int j = 0; j < 最大城市县城数; j++)
				{
					if (city_spec_temp[city_id][j] == -1)
					{
						city_spec_temp[city_id][j] = i;
						break;
					}
				}
			}

			city_spec = city_spec_temp;
		}

		void set_base_spec_relate()
		{
			array<array<int>> base_spec_temp(据点_末, array<int>(最大城市县城数, int(-1)));//初始清空

			for (int i = 0; i < 地名_末; i++)
			{
				int base_id = pk::get_building_id(ch::get_spec_pos(i));
				for (int j = 0; j < 最大据点县城数; j++)
				{
					if (base_spec_temp[base_id][j] == -1)
					{
						base_spec_temp[base_id][j] = i;
						break;
					}
				}
			}

			base_spec = base_spec_temp;
		}

		void onTurnStart(pk::force@ force)
		{

			for (int i = 0; i < 据点_末; ++i)
			{
				int force_id = pk::get_building(i).get_force_id();
				if (force_id == force.get_id())
				{
					auto base_p = ch::get_base_p(i);
					base_p.turn_init();
				}
			}
		}

		void onNewDay()
		{
			array<array<int8>> temp(4, array<int8>(5, -1));
			setting_ex[0].alliance_member_id = temp;
			for (int i = 0; i < 非贼势力_末; ++i)
			{
				int alliance_id = force_ex[i].alliance_id;
				if (alliance_id > 0 and alliance_id < 4)
				{
					setting_ex[0].add_alliance_member(alliance_id,i);
				}
			}
		}

		void onPersonDied(pk::person@ dead, pk::person@ by, pk::hex_object@ where, pk::person@ successor, int type, int rettype)
		{
			//pk::trace("onPersonDied");
			int person_id = dead.get_id();
			auto person_p = ch::get_person_p(person_id);

			//自动内政相关重置
			int base_id = person_p.auto_affairs_base;
			int role_id = person_p.auto_affairs_role;
			if (ch::is_auto_affairs_role(role_id))
			{
				if (pk::is_valid_base_id(base_id))
					ch::get_baseIA(base_id).set_charge(-1, role_id - 1);
				person_p.auto_affairs_base = 255;
				person_p.auto_affairs_role = 255;
				内政自动::calculate_building2(pk::get_building(base_id), false);
			}

			//战绩系统相关重置
			person_p.kill_unit = 0;
			person_p.troops_damage = 0;
			person_p.kill_destroyed = 0;
			person_p.kill_unit_destroyed = 0;
		}

		void onPersonChangeForce(pk::person @person, pk::force @force)
		{
			//pk::trace("onPersonChangeForce");
			int person_id = person.get_id();
			auto person_p = ch::get_person_p(person_id);
			int base_id = person_p.auto_affairs_base;
			int role_id = person_p.auto_affairs_role;
			if (ch::is_auto_affairs_role(role_id))
			{
				if (pk::is_valid_base_id(base_id))
					ch::get_baseIA(base_id).set_charge(-1, role_id - 1);
				person_p.auto_affairs_base = 255;
				person_p.auto_affairs_role = 255;
				内政自动::calculate_building2(pk::get_building(base_id), false);
			}

		}

		void onUnitRemove(pk::unit@ unit, pk::hex_object@ dst, int type)
		{
			auto unit_p = ch::get_unit_p(unit.get_id());
			unit_p.init();

			//战绩系统相关重置
			// 被消灭部队 伤害来源 类型
			pk::unit@ dst_unit = pk::hex_object_to_unit(dst);
			for (int i = 0; i < 3; i++)
			{
				if (pk::is_valid_person_id(unit.member[i]))
				{
					pk::person@ member = pk::get_person(unit.member[i]);
					auto sc_person = ch::get_person_p(unit.member[i]);
					if (type == 0)
					{
						if (temp_list.find(member.name_read) >= 0)
						{
							sc_person.kill_unit = 0;
							sc_person.troops_damage = 0;
							sc_person.kill_destroyed = 0;
							sc_person.kill_unit_destroyed = 0;
						}
						else
						{
							sc_person.kill_destroyed += 1;
							if (dst_unit !is null) sc_person.kill_unit_destroyed += 1;
						}
					}
				}
			}
		}

		void onUnitDestory(pk::unit@ attacker, pk::unit@ target)
		{
			for (int i = 0; i < 3; i++)
			{
				if (pk::is_valid_person_id(attacker.member[i]))
				{
					auto sc_person = ch::get_person_p(attacker.member[i]);
					sc_person.kill_unit += 1;
				}
			}
		}

	}

	Main main;
}
const int 组队数_末 = 300;
const int 设定_末 = 1;
const int 地名_末 = 208;
const int 地名_末2 = 207;//此数据只用于数组长度判定，存档里默认用大的
const int 最大城市县城数 = 9;
const int 最大据点县城数 = 9;

const int 预留字节_文件头 = 20;
const int 预留字节_宝物 = 70;
const int 预留字节_武将 = 120;
const int 预留字节_据点 = 500;
const int 预留字节_部队 = 30;
const int 预留字节_势力 = 120;
const int 预留字节_地名 = 100;
const int 预留字节_设定 = 300;
const int 预留字节_组队 = 20;

const int 据点结构体_int数 = 60;
const int 武将结构体_int数 = 20;
const int 部队结构体_int数 = 10;
const int 势力结构体_int数 = 40;
const int 地名结构体_int数 = 20;
const int 组队结构体_int数 = 3;
const int 设定结构体_int数 = 135;

array<BaseInfo> base_ex(据点_末);
array<personinfo> person_ex(武将_末);
array<unitinfo> unit_ex(部队_末);
array<forceinfo> force_ex(势力_末);
array<specialinfo> special_ex(地名_末);
array<settinginfo> setting_ex(设定_末);
array<autoarmyinfo> autoarmy_ex(组队数_末);

array<array<int>> city_spec(城市_末, array<int>(最大城市县城数, int(-1)));//用于储存城市和府相关信息
array<array<int>> base_spec(据点_末, array<int>(最大据点县城数, int(-1)));
const bool 新存读方法 = false;

//尝试是否可以通过序号加对应长度的方式获取对应数据？
//第x位，2个8字节
class EXdata
{
	EXdata()
	{
	}

	EXdata(int id)
	{
	}

	void init()
	{
	}

	void update(int id)
	{
	}

	void get_info(int id)
	{
	}

	void serialize(file@ f, int id)
	{
	}

	void deserialize(file@ f, int id)
	{
	}

	void serialize(pk::s11writer@ w, int id)
	{
	}

	void deserialize(pk::s11reader@ r, int id)
	{
	}

};

//存档时将结构体转为数组再存
//读档时将数组转换为结构体读取
///struct 和 class没有本质区别，只是class默认类外不可访问。不过pk2.2class是可以类外访问的
//将多个信息组合成两个int64

//好像只需要在武将死亡时初始化？或者再利用时？
class personinfo : EXdata
{
	int16 person_id;
	int8 float_command;    //统率浮动，实际用int4存，-8至+7--搞不定，还是就用int8存吧
	int8 float_strength;   //武力浮动，实际用int4存，-8至+7
	int8 float_wisdom;     //智力浮动，实际用int4存，-8至+7
	int8 float_politic;     //政治浮动，实际用int4存，-8至+7
	int8 float_charm;     //魅力浮动，实际用int4存，-8至+7

	uint8 horse_id = 255;
	uint8 weapon_id = 255;

	uint8 career;//之前的职业


	uint8 person_type = 0;		//武将类型：0-一般，1-提拔，2-提拔(预留)，4-提拔(预留)，5-小兵提拔，16-农民兵，17-府兵，18-突袭者，19-雇佣者，32-异族
	uint8 talent_type = 0;			//（实际只需要4位来存）人才类型：帅才猛将之类的---并没有用上，实际上直接存读音了
	uint8 appeared_reason = 0;		//（实际只需要4位来存）登场原因：0-无，1-提拔，2-请求仕官，3-受赏识，4-后代，5-临时
	uint8 _flag_0;				//备用

	int16 select_history_person_id = -1;//标志选拔历史武将的id
	int16 discovered_by = -1; 		//人才提拔者，或小兵的提拔者
	int8 init_force = -1;			//初次仕官势力
	int8 appeared_city = -1;		//出场城市/建筑
	int kill_num = 0;				//杀敌数---考虑到反复计算问题，还需要改函数
	int unit_kill_num = 0;			//所在部队杀敌数
	int spec_id = -1;             //封分的领地

	uint16 recruit_exp = 0;//执政官征兵经验 
	uint16 drill_exp = 0;//执政官训练经验
	uint16 inspection_exp = 0;//执政官巡查经验
	uint16 weapon_exp = 0;//执政官兵装生产经验
	uint16 siege_exp = 0;//执政官攻具生产经验
	uint16 ship_exp = 0;//执政官舰船生产经验
	uint16 build_exp = 0;//执政官筑城经验
	uint16 horse_exp = 0;//执政官产马经验

	int16 teacher_id = -1;//小兵的老师
	uint32 train_event = 0;//小兵训练时发生的事件，最终用于列传显示
	uint16 auto_affairs_base = 255;
	uint16 auto_affairs_role = 255;

	//战绩相关
	uint16 kill_unit = 0; // 击破部队数
	uint32 troops_damage = 0; // 士兵伤害数
	uint16 kill_destroyed = 0; // 被击溃总次数
	uint16 kill_unit_destroyed = 0; // 被部队溃灭次数

	//初始化
	personinfo(int person_id) override
	{
	}

	//下面这种写法用于定义全局变量，先声明，然后用get_info获取信息后使用
	personinfo() override
	{}

	void init() override
	{
		float_command = 0;    //统率浮动，实际用int4存，-8至+7--搞不定，还是就用int8存吧
		float_strength = 0;   //武力浮动，实际用int4存，-8至+7
		float_wisdom = 0;     //智力浮动，实际用int4存，-8至+7
		float_politic = 0;     //政治浮动，实际用int4存，-8至+7
		float_charm = 0;    //魅力浮动，实际用int4存，-8至+7

		horse_id = 255;
		weapon_id = 255;
		select_history_person_id = -1;//标志选拔历史武将的id

		career = 255;//之前的职业

		person_type = 0;		//武将类型：0-一般，1-提拔，2-提拔(预留)，4-提拔(预留)，5-小兵提拔，16-农民兵，17-府兵，18-突袭者，19-雇佣者，32-异族
		talent_type = 0;			//（实际只需要4位来存）人才类型：帅才猛将之类的
		appeared_reason = 0;		//（实际只需要4位来存）登场原因：0-无，1-提拔，2-请求仕官，3-受赏识，4-后代，5-临时
		_flag_0 = 0;				//备用
		//uint8 employ_year = 0;		（这个可以用登场年表示）提拔时间--暂限于武将选拔
		discovered_by = -1; 		//提拔者，或小兵的提拔者
		init_force = -1;			//初次仕官势力
		appeared_city = -1;		//出场城市/建筑
		kill_num = 0;				//杀敌数---考虑到反复计算问题，还需要改函数
		unit_kill_num = 0;			//所在部队杀敌数
		spec_id = -1;             //封分的领地

		recruit_exp = 0;//执政官征兵经验 
		drill_exp = 0;//执政官训练经验
		inspection_exp = 0;//执政官巡查经验
		weapon_exp = 0;//执政官兵装生产经验
		siege_exp = 0;//执政官攻具生产经验
		ship_exp = 0;//执政官舰船生产经验
		build_exp = 0;//执政官筑城经验
		horse_exp = 0;//执政官产马经验
		teacher_id = -1;//小兵的老师
		train_event = 0;//小兵训练时发生的事件
		auto_affairs_base = 255;
		auto_affairs_role = 255;

		kill_unit = 0; // 击破部队数
		troops_damage = 0; // 士兵伤害数
		kill_destroyed = 0; // 被击溃总次数
		kill_unit_destroyed = 0; // 被部队溃灭次数
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		//write时用
		int pre_pos = f.getPos();
		f.writeInt8(float_command);
		f.writeInt8(float_strength);
		f.writeInt8(float_wisdom);
		f.writeInt8(float_politic);
		f.writeInt8(float_charm);
		f.writeUInt8(horse_id);
		f.writeUInt8(weapon_id);
		f.writeUInt8(career);
		f.writeUInt8(person_type);
		f.writeUInt8(talent_type);
		f.writeUInt8(appeared_reason);
		f.writeUInt8(_flag_0);
		f.writeInt16(select_history_person_id);
		f.writeInt16(discovered_by);
		f.writeInt8(init_force);
		f.writeInt8(appeared_city);
		f.writeInt32(kill_num);
		f.writeInt32(unit_kill_num);
		f.writeInt32(spec_id);
		f.writeUInt16(recruit_exp);
		f.writeUInt16(drill_exp);
		f.writeUInt16(inspection_exp);
		f.writeUInt16(weapon_exp);
		f.writeUInt16(siege_exp);
		f.writeUInt16(ship_exp);
		f.writeUInt16(build_exp);
		f.writeUInt16(horse_exp);
		f.writeInt16(teacher_id);
		f.writeUInt32(train_event);
		f.writeUInt16(auto_affairs_base);
		f.writeUInt16(auto_affairs_role);
		f.writeUInt16(kill_unit);
		f.writeUInt32(troops_damage);
		f.writeUInt16(kill_destroyed);
		f.writeUInt16(kill_unit_destroyed);

		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_武将 - (after_pos - pre_pos));//f.movePos(预留字节_武将 - (after_pos - pre_pos));
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		person_id = id;
		int pre_pos = f.getPos();
		float_command = f.readInt8();
		float_strength = f.readInt8();
		float_wisdom = f.readInt8();
		float_politic = f.readInt8();
		float_charm = f.readInt8();
		horse_id = f.readUInt8();
		weapon_id = f.readUInt8();
		career = f.readUInt8();
		person_type = f.readUInt8();
		talent_type = f.readUInt8();
		appeared_reason = f.readUInt8();
		_flag_0 = f.readUInt8();
		select_history_person_id = f.readInt16();
		discovered_by = f.readInt16();
		init_force = f.readInt8();
		appeared_city = f.readInt8();
		kill_num = f.readInt32();
		unit_kill_num = f.readInt32();
		spec_id = f.readInt32();
		recruit_exp = f.readUInt16();
		drill_exp = f.readUInt16();
		inspection_exp = f.readUInt16();
		weapon_exp = f.readUInt16();
		siege_exp = f.readUInt16();
		ship_exp = f.readUInt16();
		build_exp = f.readUInt16();
		horse_exp = f.readUInt16();
		teacher_id = f.readInt16();
		train_event = f.readUInt32();
		auto_affairs_base = f.readUInt16();
		auto_affairs_role = f.readUInt16();
		kill_unit = f.readUInt16();
		troops_damage = f.readUInt32();
		kill_destroyed = f.readUInt16();
		kill_unit_destroyed = f.readUInt16();

		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_武将 - (after_pos - pre_pos));//f.movePos(预留字节_武将 - (after_pos - pre_pos));
	}

	void update_scdata(int type, int value, bool reset = false)
	{
		switch (type)
		{
			case 0:
				kill_unit = reset ? 0 : (kill_unit + value);
				break;
			case 1:
				troops_damage = reset ? 0 : (troops_damage + value);
				break;
			case 2:
				kill_destroyed = reset ? 0 : (kill_destroyed + value);
				break;
			case 3:
				kill_unit_destroyed = reset ? 0 : (kill_unit_destroyed + value);
				break;
		}
	}
}

class BaseInfo : EXdata
{
	int building_id;//作为结构信息，不进存档

	uint32 population;//人口
	uint32 mil_pop_all;//兵役人口
	uint32 mil_pop_av;//预备兵
	uint32 wounded;//伤兵
	uint8 public_order;//治安，也就港关有用
	uint16 revenue_bonus;//金收入附加值--通过事件获得
	uint16 harvest_bonus;//粮收入附加值--通过事件获得
	uint16 base_revenue;
	uint16 base_harvest;
	uint8 city_level;


	uint8 return_timer;//回归计时器--此设定需游戏中说明，据点攻占后设置计数为9，如果在指定回合内能触发回归buf，则设置为5，即是5回合的回归buf
	uint8 return_buf_timer;//满足条件后，加强人口返回的buf时间，取代bool return_buf;
	uint32 return_pop;//待返回人口


	//下方这些都是太守自治内容
	int16 recruit_person;//征兵执行官
	int16 inspections_person;//巡查执行官
	int16 drill_person;//训练执行官
	int16 produce_person;//生产执行官
	uint8 auto_sequence;//自动化顺序
	uint8 inspections_std;//巡察标准
	uint8 drill_std;//训练标准
	uint8 recruit_std_foodtroop;//征兵标准，粮兵比
	uint8 recruit_std_porder;//征兵标准，治安
	uint32 recruit_std_gold;//征兵标准，金
	uint8 reward_std;//褒赏标准，忠诚

	//！！！！下方int8数据需每回合重置！！！！！！！
	uint8 anti_rumor;//防流言计数，警戒等级，没旬减1
	uint8 provoke_cd;//被挑衅的cd,每回合自动减少，被挑衅时设置cd，据点所属变化时清零
	uint8 farmer_count;//一回合可以进行农民兵召唤的次数

	array<uint8> spy_lv(势力_末, 0);////如果用这个判断间谍等级的话，需要16个uint32，或者限制数字小于16，则本质上是uint4，这样只用8

	bool can_inspections;//巡察许可-目前限城市
	bool can_drill;//训练许可-目前限城市，可扩展
	bool can_recruit;//征兵许可-目前限城市
	bool can_reward;//褒奖许可-目前限城市，可扩展
	bool can_transport;//运输许可-目前限城市，可扩展
	array<bool> can_produce(兵种_末, false);//枪戟弩马兵器水军

	array<bool> can_build(势力_末, false);//根据势力区分的是否可以拆建的信息

	//array<bool> has_spy(势力_末, false);////判断是否有细作的专门数组，需要获取势力id，需要两个uint32
	//0代表无间谍，1-5逐渐开放信息？。或者用uint4？0代表无，1-15代表等级，占5.875个int32
	array<bool> send_spy(势力_末, false);//根据势力区分的是否向该城市派驻间谍
	array<bool> enhance_spy(势力_末, false);//根据势力区分的是否向该城市发布加强间谍信息

	//！！！！下方bool数据需每回合重置！！！！！！！
	bool recruit_done;//是否已征兵-港关
	bool inspections_done;//是否已巡察-港关

	bool mobilize_done;//紧急动员完成
	bool repair_done;//城墙维修完成
	bool enlist_done;//募兵完成
	bool perturb_done;//据点计略扰乱
	bool misinform_done;//据点计略伪报
	bool fire_done;//据点计略火计
	bool beguile_done;//据点计略攻心
	bool raid_done;//据点计略奇袭
	bool reinforce_done;//据点计略援军
	bool bargaining_done;//讨价还价
	bool weapon_merchant_done;//兵装买卖

	//自动内政结构体
	BuildingInfo2 IA_info;

	//初始化
	BaseInfo(int base_id) override
	{
	}

	BaseInfo() override {}

	void init() override
	{
		population = 0;//人口
		mil_pop_all = 0;//兵役人口
		mil_pop_av = 0;//预备兵
		wounded = 0;//伤兵
		return_timer = 0;//回归计时器--此设定需游戏中说明
		return_pop = 0;//待返回人口
		return_buf_timer = 0;
		//bool can_build;//是否可拆建

		can_inspections = false;//巡察许可-目前限城市
		can_drill = false;//训练许可-目前限城市，可扩展
		can_recruit = false;//征兵许可-目前限城市
		can_reward = false;//褒奖许可-目前限城市，可扩展
		can_transport = false;//运输许可-目前限城市，可扩展
		for (int i = 0; i < 兵种_末; ++i)
			can_produce[i] = false;//枪戟弩马兵器水军

		recruit_person = -1;//征兵执行官
		inspections_person = -1;//巡查执行官
		drill_person = -1;//训练执行官
		produce_person = -1;//生产执行官

		auto_sequence = 1;//自动化顺序
		inspections_std = 95;//巡察标准
		drill_std = 95;//训练标准
		recruit_std_foodtroop = 150;//征兵标准，粮兵比
		recruit_std_porder = 95;//征兵标准，治安
		recruit_std_gold = 2500;//征兵标准，金
		reward_std = 90;//褒赏标准，忠诚
		//array<bool> has_spy(势力_末, false);////判断是否有细作的专门数组，需要获取势力id，需要两个uint32
		//0代表无间谍，1-5逐渐开放信息？。或者用uint4？0代表无，1-15代表等级，占5.875个int32
		for (int i = 0; i < 势力_末; ++i)
		{
			spy_lv[i] = 0;//如果用这个判断间谍等级的话，需要16个uint32，或者限制数字小于16，则本质上是uint4，这样只用8
			send_spy[i] = false;//根据势力区分的是否向该城市派驻间谍
			enhance_spy[i] = false;//根据势力区分的是否向该城市发布加强间谍信息
			can_build[i] = true;//根据势力区分的是否可以拆建的信息
		}

		public_order = 85;//治安，也就港关有用
		anti_rumor = 0;//防流言计数

		revenue_bonus = 0;//金收入附加值--通过事件获得
		harvest_bonus = 0;//粮收入附加值--通过事件获得
		base_revenue = 0;
		base_harvest = 0;
		city_level = 0;

		IA_info.init();
		//！！！！下方数据需每回合重置！！！！！！！
		//可以考虑做成常量加array形式？---

		turn_init(true);
	}

	void turn_init(bool reset = false)
	{
		if (reset)
		{
			provoke_cd = 0;//被挑衅的cd,每回合自动减少，被挑衅时设置cd，据点所属变化时清零
			anti_rumor = 0;
		}
		else if (provoke_cd > 0)
		{
			provoke_cd -= 1;
			anti_rumor -= 1;
		}
		recruit_done = false;//是否已征兵-港关
		inspections_done = false;//是否已巡察-港关

		mobilize_done = false;//紧急动员完成
		repair_done = false;//城墙维修完成
		enlist_done = false;//募兵完成
		perturb_done = false;//据点计略扰乱
		misinform_done = false;//据点计略伪报
		fire_done = false;//据点计略火计
		beguile_done = false;//据点计略攻心
		raid_done = false;//据点计略攻心
		reinforce_done = false;//据点计略援军
		bargaining_done = false;//讨价还价
		weapon_merchant_done = false;//兵装买卖

		farmer_count = 3;//一回合可以进行农民兵召唤的次数
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		//write
		int pre_pos = f.getPos();
		f.writeUInt32(population);
		f.writeUInt32(mil_pop_all);
		f.writeUInt32(mil_pop_av);
		f.writeUInt32(wounded);
		f.writeUInt16(revenue_bonus);
		f.writeUInt16(harvest_bonus);
		f.writeUInt16(base_revenue);
		f.writeUInt16(base_harvest);
		f.writeUInt8(public_order);
		f.writeUInt8(city_level);
		f.writeUInt8(return_timer);
		f.writeUInt8(return_buf_timer);
		f.writeUInt32(return_pop);
		f.writeInt16(recruit_person);
		f.writeInt16(inspections_person);
		f.writeInt16(drill_person);
		f.writeInt16(produce_person);
		f.writeUInt8(auto_sequence);
		f.writeUInt8(inspections_std);
		f.writeUInt8(drill_std);
		f.writeUInt8(recruit_std_foodtroop);
		f.writeUInt32(recruit_std_gold);
		f.writeUInt8(reward_std);
		f.writeUInt8(recruit_std_porder);
		for (int i = 0; i < 势力_末; ++i)
			f.writeUInt8(spy_lv[i]);
		f.writeUInt8(anti_rumor);
		f.writeUInt8(provoke_cd);
		f.writeUInt8(farmer_count);

		f.writeBool(can_inspections);
		f.writeBool(can_drill);
		f.writeBool(can_recruit);
		f.writeBool(can_reward);
		f.writeBool(can_transport);
		for (int i = 0; i < 兵种_末; ++i)
			f.writeBool(can_produce[i]);
		for (int i = 0; i < 势力_末; ++i)
		{
			f.writeBool(can_build[i]);
			f.writeBool(send_spy[i]);
			f.writeBool(enhance_spy[i]);
		}
		f.writeBool(recruit_done);
		f.writeBool(inspections_done);
		f.writeBool(mobilize_done);
		f.writeBool(repair_done);
		f.writeBool(enlist_done);
		f.writeBool(perturb_done);
		f.writeBool(misinform_done);
		f.writeBool(fire_done);
		f.writeBool(beguile_done);
		f.writeBool(raid_done);
		f.writeBool(reinforce_done);
		f.writeBool(bargaining_done);
		f.writeBool(weapon_merchant_done);

		//还需考虑存档调整时预留字节问题
		IA_info.serialize(f, id);
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_据点 - (after_pos - pre_pos));//f.movePos(预留字节_据点 - (after_pos - pre_pos));
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		building_id = id;
		int pre_pos = f.getPos();
		population = f.readUInt32();
		mil_pop_all = f.readUInt32();
		mil_pop_av = f.readUInt32();
		wounded = f.readUInt32();
		revenue_bonus = f.readUInt16();
		harvest_bonus = f.readUInt16();
		base_revenue = f.readUInt16();
		base_harvest = f.readUInt16();
		public_order = f.readUInt8();
		city_level = f.readUInt8();
		return_timer = f.readUInt8();
		return_buf_timer = f.readUInt8();
		return_pop = f.readUInt32();
		recruit_person = f.readInt16();
		inspections_person = f.readInt16();
		drill_person = f.readInt16();
		produce_person = f.readInt16();
		auto_sequence = f.readUInt8();
		inspections_std = f.readUInt8();
		drill_std = f.readUInt8();
		recruit_std_foodtroop = f.readUInt8();
		recruit_std_gold = f.readUInt32();
		reward_std = f.readUInt8();
		recruit_std_porder = f.readUInt8();
		for (int i = 0; i < 势力_末; ++i)
			spy_lv[i] = f.readUInt8();
		anti_rumor = f.readUInt8();
		provoke_cd = f.readUInt8();
		farmer_count = f.readUInt8();


		can_inspections = f.readBool();
		can_drill = f.readBool();
		can_recruit = f.readBool();
		can_reward = f.readBool();
		can_transport = f.readBool();
		for (int i = 0; i < 兵种_末; ++i)
			can_produce[i] = f.readBool();
		for (int i = 0; i < 势力_末; ++i)
		{
			can_build[i] = f.readBool();
			send_spy[i] = f.readBool();
			enhance_spy[i] = f.readBool();
		}
		recruit_done = f.readBool();
		inspections_done = f.readBool();
		mobilize_done = f.readBool();
		repair_done = f.readBool();
		enlist_done = f.readBool();
		perturb_done = f.readBool();
		misinform_done = f.readBool();
		fire_done = f.readBool();
		beguile_done = f.readBool();
		raid_done = f.readBool();
		reinforce_done = f.readBool();
		bargaining_done = f.readBool();
		weapon_merchant_done = f.readBool();

		//还需考虑存档调整时预留字节问题
		IA_info.deserialize(f, id);
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_据点 - (after_pos - pre_pos));//f.movePos(预留字节_据点 - (after_pos - pre_pos));
	}

}

class BuildingInfo2 : EXdata
{
	int building_id;
	uint16 troops_effic; // 征兵开支
	uint16 porder_effic; // 巡查开支
	uint16 train_effic; // 训练开支
	uint16 weapon_effic; // 兵装开支
	uint16 horse_effic;// 马开支
	uint16 punch_effic;// 攻具开支
	uint16 boat_effic; // 船开支
	uint16 repair_effic; // 筑城开支

	int16 recruit_person;// 征兵执行官
	int16 inspections_person; // 巡查执行官
	int16 drill_person;// 训练执行官
	int16 weapon_person;// 兵装执行官
	int16 horse_person;// 马执行官
	int16 punch_person;// 攻具执行官
	int16 boat_person;// 造船执行官

	uint16 troops_gain; // 征兵增量
	uint16 porder_gain; // 巡查增量
	uint16 train_gain; // 训练增量
	uint16 spear_gain; // 枪增量
	uint16 halberd_gain;// 戟增量
	uint16 bow_gain; // 弩增量
	uint16 horse_gain; // 马增量
	uint16 well_gain; // 井栏增量
	uint16 punch_gain; // 冲车增量
	uint16 boat_gain; // 船增量
	uint16 repair_gain; // 筑城增量

	uint16 building_revenue;// 据点下一旬收入
	uint16 weapon_expense; // 兵装维护费
	uint16 troops_expense; // 军饷
	uint16 building_policy; // 征兵方针
	uint16 policy_expense; // 征兵方针开支

	uint16 well;  // 井栏量(用于存储临时产量)
	uint16 punch;  // 冲车量(用于存储临时产量)
	uint16 boat;  // 舰船量(用于存储临时产量)
	uint8 weapon_choose;// 选择哪种兵装
	uint8 arms_choose;  // 选择哪种工器

	uint16 city_defense; // 额外城防

	array<uint8> rank_type = { 内政自动化_招兵, 内政自动化_兵装, 内政自动化_巡查, 内政自动化_训练, 内政自动化_攻具, 内政自动化_育马, 内政自动化_造船 };

	void init() override
	{
		troops_effic = 0;
		porder_effic = 0;
		train_effic = 0;
		weapon_effic = 0;
		horse_effic = 0;
		punch_effic = 0;
		boat_effic = 0;
		repair_effic = 0;

		recruit_person = -1;
		inspections_person = -1;
		drill_person = -1;
		weapon_person = -1;
		horse_person = -1;
		punch_person = -1;
		boat_person = -1;

		troops_gain = 0;
		porder_gain = 0;
		train_gain = 0;
		spear_gain = 0;
		halberd_gain = 0;
		bow_gain = 0;
		horse_gain = 0;
		well_gain = 0;
		punch_gain = 0;
		boat_gain = 0;
		repair_gain = 0;

		building_revenue = 0;
		weapon_expense = 0;
		troops_expense = 0;
		building_policy = 2;
		policy_expense = 0;

		well = 0;
		punch = 0;
		boat = 0;
		weapon_choose = 0;
		arms_choose = 0;

		city_defense = 0;
		rank_type = { 内政自动化_招兵, 内政自动化_兵装, 内政自动化_巡查, 内政自动化_训练, 内政自动化_攻具, 内政自动化_育马, 内政自动化_造船 };
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		//因为此处存读作为base_ex的一部分，所以不需要move_pos
		f.writeUInt16(troops_effic);
		f.writeUInt16(porder_effic);
		f.writeUInt16(train_effic);
		f.writeUInt16(weapon_effic);
		f.writeUInt16(horse_effic);
		f.writeUInt16(punch_effic);
		f.writeUInt16(boat_effic);
		f.writeUInt16(repair_effic);

		f.writeInt16(recruit_person);
		f.writeInt16(inspections_person);
		f.writeInt16(drill_person);
		f.writeInt16(weapon_person);
		f.writeInt16(horse_person);
		f.writeInt16(punch_person);
		f.writeInt16(boat_person);

		f.writeUInt16(troops_gain);
		f.writeUInt16(porder_gain);
		f.writeUInt16(train_gain);
		f.writeUInt16(spear_gain);
		f.writeUInt16(halberd_gain);
		f.writeUInt16(bow_gain);
		f.writeUInt16(horse_gain);
		f.writeUInt16(well_gain);
		f.writeUInt16(punch_gain);
		f.writeUInt16(boat_gain);
		f.writeUInt16(repair_gain);

		f.writeUInt16(building_revenue);
		f.writeUInt16(weapon_expense);
		f.writeUInt16(troops_expense);
		f.writeUInt16(building_policy);
		f.writeUInt16(policy_expense);

		f.writeUInt16(well);
		f.writeUInt16(punch);
		f.writeUInt16(boat);
		f.writeUInt8(weapon_choose);
		f.writeUInt8(arms_choose);

		f.writeUInt16(city_defense);
		for (int i = 0; i < 7; ++i)
			f.writeUInt8(rank_type[i]);
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		building_id = id;
		//因为此处存读作为base_ex的一部分，所以不需要move_pos
		troops_effic = f.readUInt16();
		porder_effic = f.readUInt16();
		train_effic = f.readUInt16();
		weapon_effic = f.readUInt16();
		horse_effic = f.readUInt16();
		punch_effic = f.readUInt16();
		boat_effic = f.readUInt16();
		repair_effic = f.readUInt16();

		recruit_person = f.readInt16();
		inspections_person = f.readInt16();
		drill_person = f.readInt16();
		weapon_person = f.readInt16();
		horse_person = f.readInt16();
		punch_person = f.readInt16();
		boat_person = f.readInt16();

		troops_gain = f.readUInt16();
		porder_gain = f.readUInt16();
		train_gain = f.readUInt16();
		spear_gain = f.readUInt16();
		halberd_gain = f.readUInt16();
		bow_gain = f.readUInt16();
		horse_gain = f.readUInt16();
		well_gain = f.readUInt16();
		punch_gain = f.readUInt16();
		boat_gain = f.readUInt16();
		repair_gain = f.readUInt16();

		building_revenue = f.readUInt16();
		weapon_expense = f.readUInt16();
		troops_expense = f.readUInt16();
		building_policy = f.readUInt16();
		policy_expense = f.readUInt16();

		well = f.readUInt16();
		punch = f.readUInt16();
		boat = f.readUInt16();
		weapon_choose = f.readUInt8();
		arms_choose = f.readUInt8();

		city_defense = f.readUInt16();
		for (int i = 0; i < 7; ++i)
			rank_type[i] = f.readUInt8();
	}

	///////////////////////////////相关支持函数///////////////////////////////////

	/*get_effic, set_effic, set_choose, get_choose */

	void set_charge(int person_id, int 内政自动化_项目)
	{
		int origin_person_id;
		switch (内政自动化_项目)
		{
			case 内政自动化_巡查:
				origin_person_id = inspections_person;
				inspections_person = person_id;
				break;
			case 内政自动化_训练:
				origin_person_id = drill_person;
				drill_person = person_id;
				break;
			case 内政自动化_招兵:
				origin_person_id = recruit_person;
				recruit_person = person_id;
				break;
			case 内政自动化_兵装:
				origin_person_id = weapon_person;
				weapon_person = person_id;
				break;
			case 内政自动化_育马:
				origin_person_id = horse_person;
				horse_person = person_id;
				break;
			case 内政自动化_攻具:
				origin_person_id = punch_person;
				punch_person = person_id;
				break;
			case 内政自动化_造船:
				origin_person_id = boat_person;
				boat_person = person_id;
				break;
		}

		if (pk::is_valid_person_id(origin_person_id))
		{
			person_ex[origin_person_id].auto_affairs_base = 255;
			person_ex[origin_person_id].auto_affairs_role = 255;
		}

		if (pk::is_valid_person_id(person_id))
		{
			int service = pk::get_person(person_id).service;
			ch::get_person_p(person_id).auto_affairs_base = service == -1 ? 255 : service;// building_id;//
			ch::get_person_p(person_id).auto_affairs_role = 内政自动化_项目 + 1;
		}
	}

	int get_charge(int 内政自动化_项目)
	{
		int person_id = -1;
		switch (内政自动化_项目)
		{
			case 内政自动化_巡查:
				person_id = inspections_person;
				break;
			case 内政自动化_训练:
				person_id = drill_person;
				break;
			case 内政自动化_招兵:
				person_id = recruit_person;
				break;
			case 内政自动化_兵装:
				person_id = weapon_person;
				break;
			case 内政自动化_育马:
				person_id = horse_person;
				break;
			case 内政自动化_攻具:
				person_id = punch_person;
				break;
			case 内政自动化_造船:
				person_id = boat_person;
				break;
		}
		return person_id;
	}

	string get_charge_name(int 内政自动化_项目)
	{
		string charge_name = '';
		switch (内政自动化_项目)
		{
			case 内政自动化_巡查:
				charge_name = '巡查执行官';
				break;
			case 内政自动化_训练:
				charge_name = '训练执行官';
				break;
			case 内政自动化_招兵:
				charge_name = '招兵执行官';
				break;
			case 内政自动化_兵装:
				charge_name = '兵装生产官';
				break;
			case 内政自动化_育马:
				charge_name = '育马执行官';
				break;
			case 内政自动化_攻具:
				charge_name = '攻具生产官';
				break;
			case 内政自动化_造船:
				charge_name = '造船执行官';
				break;
		}
		return charge_name;
	}

	int get_effic(int 内政自动化_项目)
	{
		int effic = 0;
		switch (内政自动化_项目)
		{
			case 内政自动化_巡查:
				effic = porder_effic;
				break;
			case 内政自动化_训练:
				effic = train_effic;
				break;
			case 内政自动化_招兵:
				effic = troops_effic;
				break;
			case 内政自动化_兵装:
				effic = weapon_effic;
				break;
			case 内政自动化_育马:
				effic = horse_effic;
				break;
			case 内政自动化_攻具:
				effic = punch_effic;
				break;
			case 内政自动化_造船:
				effic = boat_effic;
				break;
			case 内政自动化_筑城:
				effic = repair_effic;
				break;
		}
		return effic;
	}

	void set_effic(int effic, int 内政自动化_项目)
	{
		switch (内政自动化_项目)
		{
			case 内政自动化_巡查:
				porder_effic = effic;
				break;
			case 内政自动化_训练:
				train_effic = effic;
				break;
			case 内政自动化_招兵:
				troops_effic = effic;
				break;
			case 内政自动化_兵装:
				weapon_effic = effic;
				break;
			case 内政自动化_育马:
				horse_effic = effic;
				break;
			case 内政自动化_攻具:
				punch_effic = effic;
				break;
			case 内政自动化_造船:
				boat_effic = effic;
				break;
			case 内政自动化_筑城:
				repair_effic = effic;
				break;
		}
	}

	int get_choose(int 内政自动化_项目)
	{
		int choose = -1;
		switch (内政自动化_项目)
		{
			case 内政自动化_兵装:
				choose = weapon_choose;
				break;
			case 内政自动化_攻具:
				choose = arms_choose;
				break;
			default:
				choose = -1;
		}
		return choose;
	}

	void set_choose(int choose, int 内政自动化_项目)
	{
		switch (内政自动化_项目)
		{
			case 内政自动化_兵装:
				weapon_choose = choose;
				break;
			case 内政自动化_攻具:
				arms_choose = choose;
				break;
		}
	}

	string get_choose_name(int base_id, int 内政自动化_项目)
	{
		if (内政自动化_项目 == 内政自动化_兵装)
		{
			array<string> weapon_list = { '平衡', '生产枪', '生产戟', '生产弩' };
			return weapon_list[weapon_choose];
		}
		else if (内政自动化_项目 == 内政自动化_攻具)
		{
			pk::building@ building = pk::get_building(base_id);
			array<string> arms_list = { '平衡', pk::has_tech(building, 技巧_投石开发) ? '投石' : '井阑' , pk::has_tech(building, 技巧_木兽开发) ? '木兽' : '冲车' };
			return arms_list[arms_choose];
		}
		return '';
	}

	string get_choose_name2(int base_id, int 内政自动化_项目)
	{
		if (内政自动化_项目 == 内政自动化_兵装)
		{
			array<string> weapon_list = { '各项', '枪', '戟', '弩' };
			return weapon_list[weapon_choose];
		}
		else if (内政自动化_项目 == 内政自动化_攻具)
		{
			pk::building@ building = pk::get_building(base_id);
			array<string> arms_list = { '各项', pk::has_tech(building, 技巧_投石开发) ? '投石' : '井阑' , pk::has_tech(building, 技巧_木兽开发) ? '木兽' : '冲车' };
			return arms_list[arms_choose];
		}
		return '';
	}

	int get_gain(int 内政自动化_项目)
	{
		int gain = 0;
		switch (内政自动化_项目)
		{
			case 内政自动化_巡查:
				gain = porder_gain;
				break;
			case 内政自动化_训练:
				gain = train_gain;
				break;
			case 内政自动化_招兵:
				gain = troops_gain;
				break;
			case 内政自动化_兵装:
				if (weapon_choose == 0 or weapon_choose == 1)
					gain = spear_gain;
				else if (weapon_choose == 2)
					gain = halberd_gain;
				else if (weapon_choose == 3)
					gain = bow_gain;
				break;
			case 内政自动化_育马:
				gain = horse_gain;
				break;
			case 内政自动化_攻具:
				if (arms_choose == 0 or arms_choose == 1)
					gain = well_gain;
				else if (arms_choose == 2)
					gain = punch_gain;
				break;
			case 内政自动化_造船:
				gain = boat_gain;
				break;
			case 内政自动化_筑城:
				gain = repair_gain;
				break;
		}
		return gain;
	}

	int get_stat_type(int 内政自动化_项目)
	{
#if param_set
		switch (内政自动化_项目)
		{
			case 内政自动化_招兵:
				return pk::get_recruit_param().stat;
			case 内政自动化_训练:
				return pk::get_drill_param().stat;
			case 内政自动化_巡查:
				return pk::get_patrol_param().stat;
			case 内政自动化_兵装:
			case 内政自动化_育马:
			case 内政自动化_攻具:
			case 内政自动化_造船:
				return pk::get_produce_param().stat;
			case 内政自动化_筑城:
				return -1;
			default:
				break;
		}
#endif
#if not_param_set
		switch (内政自动化_项目)
		{
			case 内政自动化_招兵:
				return int(pk::core["recruit.stat"]);
			case 内政自动化_训练:
				return int(pk::core["train.stat"]);
			case 内政自动化_巡查:
				return int(pk::core["inspection.stat"]);
			case 内政自动化_兵装:
				return int(pk::core["weapon_produce.stat"]);
			case 内政自动化_育马:
				return int(pk::core["weapon_produce.stat"]);
			case 内政自动化_攻具:
				return int(pk::core["weapon_produce.stat"]);
			case 内政自动化_造船:
				return int(pk::core["weapon_produce.stat"]);
			case 内政自动化_筑城:
				return -1;
			default:
				break;
		}
#endif
		return -1;
	}

	int get_required_skill(int 内政自动化_项目)
	{
#if param_set
		switch (内政自动化_项目)
		{
			case 内政自动化_招兵:
				return pk::get_recruit_param().skill;
			case 内政自动化_训练:
				return 特技_调练;
			case 内政自动化_巡查:
				return 特技_巡查;
			case 内政自动化_兵装:
				return pk::get_produce_param().smith_skill;
			case 内政自动化_育马:
				return pk::get_produce_param().stable_skill;
			case 内政自动化_攻具:
				return pk::get_produce_param().workshop_skill;
			case 内政自动化_造船:
				return pk::get_produce_param().shipyard_skill;
			case 内政自动化_筑城:
				return -1;
			default:
				break;
		}
#endif
#if not_param_set
		switch (内政自动化_项目)
		{
			case 内政自动化_招兵:
				return int(pk::core["recruit.skill"]);
			case 内政自动化_训练:
				return 特技_调练;
			case 内政自动化_巡查:
				return 特技_巡查;
			case 内政自动化_兵装:
				return int(pk::core["weapon_produce.smith_skill"]);
			case 内政自动化_育马:
				return int(pk::core["weapon_produce.stable_skill"]);
			case 内政自动化_攻具:
				return int(pk::core["weapon_produce.workshop_skill"]);
			case 内政自动化_造船:
				return int(pk::core["weapon_produce.shipyard_skill"]);
			case 内政自动化_筑城:
				return 特技_筑城;
			default:
				break;
		}
#endif
		return -1;
	}

	int get_effect_stat(int 内政自动化_项目, pk::person@ person = @null)
	{
		int result = 0;
		if (person is null) @ person = pk::get_person(get_charge(内政自动化_项目));//可以不传入值，不传入时默认选当前设置值
		if (pk::is_alive(person))
		{
			int skill_id = get_required_skill(内政自动化_项目);
			int mul = ch::has_skill(person, skill_id) ? pk::core::skill_constant_value(特技_急袭) : 0;
			int stat = person.stat[get_stat_type(内政自动化_项目)];
			result = stat * 2 * (1 + mul);
		}
		return result;
	}

	int get_stat_rank(int 内政自动化_项目, pk::person@ person = @null)
	{
		int effect_stat = get_effect_stat(内政自动化_项目, person);
		if (effect_stat >= 190) return 0;
		else if (effect_stat >= 170) return 1;
		else if (effect_stat >= 150) return 2;
		else return 3;
	}

	uint get_rank_color(int stat_rank)
	{
		switch (stat_rank)
		{
			case 0:
				return 0x60fcb50b;//金色
			case 1:
				return 0x60cc37ec;//紫色
			case 2:
				return 0x602b88f6;//蓝色
			case 3:
				return 0x60eff3f3;//灰色
			default:
				break;
		}
		return 0x60cc37ec;//灰色
	}

	int get_all_effic()
	{
		int effic = 0;
		for (int i = 0; i <= 内政自动化_造船; i += 1)
		{
			if (pk::is_valid_person_id(get_charge(i)))
			{
				effic += get_effic(i);
			}
		}

		effic += repair_effic;
		return effic;
	}

}

class unitinfo : EXdata//需要在部队生成的时候初始化，还是毁灭时？
{
	int unit_id;
	//int id;//结构初始化时获得，update时直接用？那嵌套还可以用吗
	bool has_contact;//和所有其他部队初次作战还是和玩家初次作战？
	bool has_luezhen;//判断本回合是否被掠阵
	uint8 cd_1;//各种特技cd
	uint8 cd_2;//各种特技cd
	uint8 cd_3;//各种特技cd
	uint8 cd_4;//各种特技cd
	uint8 cd_5;//各种特技cd
	uint8 cd_6;//各种特技cd
	uint8 cd_7;//各种特技cd
	uint8 cd_8;//各种特技cd
	uint16 wounded;//伤兵
	uint8 movement_remain;//移动及迷雾相关的数据重新放回core2,此项作废

	int8 order = 部队任务_末;
	int target;
	int target_type;
	int8 pos_x;
	int8 pos_y;
	bool setting = false;
	//uint16 type; // 部队类型 
	//初始化
	unitinfo(int id) override
	{
	}
	//因为没有需要id，所以如果写下面这种，会导致前面的被冲掉，所以就不用提供下面这张声明方式了
	//下面这种写法用于定义全局变量，先声明，然后用get_info获取信息后使用
	unitinfo() override {}

	void init() override
	{
		turn_init();
		clear_ssunit_data();
		wounded = 0;
		uint8 movement_remain = 0;

		//下方无用暂不写
		cd_1 = 0;
		cd_2 = 0;
		cd_3 = 0;
		cd_4 = 0;
		cd_5 = 0;
		cd_6 = 0;
		cd_7 = 0;
		cd_8 = 0;
	}

	void turn_init()
	{
		has_contact = false;
		has_luezhen = false;
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		//因为移动力实际上在core2内部，所以特殊处理
		int pre_pos = f.getPos();
		f.writeBool(has_contact);
		f.writeBool(has_luezhen);
		f.writeUInt16(wounded);
		f.writeUInt8(movement_remain);

		f.writeInt8(order);
		f.writeInt32(target);
		f.writeInt32(target_type);
		f.writeInt8(pos_x);
		f.writeInt8(pos_y);
		f.writeBool(setting);

		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_部队 - (after_pos - pre_pos));//f.movePos(预留字节_部队 - (after_pos - pre_pos));
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		unit_id = id;
		int pre_pos = f.getPos();
		has_contact = f.readBool();
		has_luezhen = f.readBool();
		wounded = f.readUInt16();
		movement_remain = f.readUInt8();

		order = f.readInt8();
		target = f.readInt32();
		target_type = f.readInt32();
		pos_x = f.readInt8();
		pos_y = f.readInt8();
		setting = f.readBool();

		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_部队 - (after_pos - pre_pos));//f.movePos(预留字节_部队 - (after_pos - pre_pos));

	}

	void clear_ssunit_data()
	{
		order = 部队任务_末;
		target = 0;
		target_type = 0;
		pos_x = 0;
		pos_y = 0;
		setting = false;
	}

	void set_ssunit_data(pk::unit@ unit)
	{
		order = unit.order;
		target = unit.target;
		target_type = unit.target_type;
		pos_x = unit.pos.x;
		pos_y = unit.pos.y;
		setting = true;
	}

}

class forceinfo : EXdata
{
	int force_id;
	int8 good_evil;
	uint8 investment_time;
	uint16 investment_gold;
	uint8 disaster_relief_time;//灾民报恩
	bool jisi_done;//是否执行过祭祀

	bool all_ability_researched;


	//异族协同请求
	array<int8> ask_base_id(3, int8(-1));//长度为三的请求方据点id数组
	array<int8> aim_city_id(3, int8(-1));//长度为三的目标城市id数组
	array<int8> yizu_force_id(3, int8(-1));//长度为三的异族势力id数组
	array<int8> wait_timer(3, int8(-1));//长度为三的多少旬后出兵数组

	//被几号玩家流言次数
	array<uint8> rumor_timer(8, uint8(0));

	int8 alliance_id;
	int8 attack_delay;//进攻延迟
	int8 form_alliance_delay;


	//小兵相关数据
	int16 talent_id = -1;
	int16 discovered_by = -1;
	int16 teacher_id = -1;
	array<uint8> max_stat(武将能力_末, uint8(-1));
	array<uint8> init_stat(武将能力_末, uint8(-1));
	uint8 talent_status = 0;
	uint8 remained_time = 0;
	bool time_extended = false;
	bool is_out = false;
	uint32 train_event = 0;//32位来存26个事件是否发生过
	array<uint8> recent_special_event = { 0,0,0 };//因为0号事件不会发生
	uint8 teaching_method = 0;
	int8 out_time = 0;
	bool talent_event_happened;//储存每回合是否发生过事件
	//初始化
	forceinfo(int force_id) override
	{
	}
	//下面这种写法用于定义全局变量，先声明，然后用get_info获取信息后使用
	forceinfo() override {}

	void init() override
	{
		good_evil = 0;
		investment_time = uint8(-1);//投资预计回报时间
		investment_gold = uint16(-1);//投资金钱
		disaster_relief_time = uint8(-1);//灾民报恩
		jisi_done = false;//是否执行过祭祀

		all_ability_researched = false;

		//异族协同请求
		ask_base_id = { -1,-1,-1 };
		aim_city_id = { -1,-1,-1 };
		yizu_force_id = { -1,-1,-1 };
		wait_timer = { -1,-1,-1 };

		rumor_timer = { 0,0,0,0,0,0,0,0 };//被几号玩家流言次数

		alliance_id = -1;
		attack_delay = -1;
		form_alliance_delay = -1;

		init_talent_info();
	}

	void init_talent_info()
	{
		//小兵相关数据
		talent_id = -1;
		discovered_by = -1;
		teacher_id = -1;
		max_stat = { 0,0,0,0,0 };
		init_stat = { 0,0,0,0,0 };
		talent_status = 0;
		remained_time = 0;
		time_extended = false;
		is_out = false;
		train_event = 0;//32位来存26个事件是否发生过
		recent_special_event = { 0,0,0 };//因为0号事件不会发生
		teaching_method = 0;
		out_time = 0;
		talent_event_happened = false;
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		int pre_pos = f.getPos();
		f.writeInt8(good_evil);
		f.writeUInt8(investment_time);
		f.writeUInt16(investment_gold);
		f.writeUInt8(disaster_relief_time);
		f.writeBool(jisi_done);
		f.writeBool(all_ability_researched);
		for (int i = 0; i < 3; ++i)
		{
			f.writeInt8(ask_base_id[i]);
			f.writeInt8(aim_city_id[i]);
			f.writeInt8(yizu_force_id[i]);
			f.writeInt8(wait_timer[i]);
		}
		for (int i = 0; i < 8; ++i)
		{
			f.writeUInt8(rumor_timer[i]);
		}
		f.writeInt8(alliance_id);
		f.writeInt8(attack_delay);
		f.writeInt8(form_alliance_delay);
		f.writeInt16(talent_id);
		f.writeInt16(discovered_by);
		f.writeInt16(teacher_id);
		for (int i = 0; i < 武将能力_末; ++i)
		{
			f.writeUInt8(max_stat[i]);
			f.writeUInt8(init_stat[i]);
		}

		f.writeUInt8(talent_status);
		f.writeUInt8(remained_time);
		f.writeBool(time_extended);
		f.writeBool(is_out);
		f.writeUInt32(train_event);
		for (int i = 0; i < 3; ++i)
		{
			f.writeUInt8(recent_special_event[i]);
		}
		f.writeUInt8(teaching_method);
		f.writeInt8(out_time);
		f.writeBool(talent_event_happened);
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_势力 - (after_pos - pre_pos));//f.movePos(预留字节_势力 - (after_pos - pre_pos));
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		force_id = id;
		int pre_pos = f.getPos();
		good_evil = f.readInt8();
		investment_time = f.readUInt8();
		investment_gold = f.readUInt16();
		disaster_relief_time = f.readUInt8();
		jisi_done = f.readBool();
		all_ability_researched = f.readBool();
		for (int i = 0; i < 3; ++i)
		{
			ask_base_id[i] = f.readInt8();
			aim_city_id[i] = f.readInt8();
			yizu_force_id[i] = f.readInt8();
			wait_timer[i] = f.readInt8();
		}
		for (int i = 0; i < 8; ++i)
			rumor_timer[i] = f.readUInt8();
		alliance_id = f.readInt8();
		attack_delay = f.readInt8();
		form_alliance_delay = f.readInt8();
		talent_id = f.readInt16();
		discovered_by = f.readInt16();
		teacher_id = f.readInt16();
		for (int i = 0; i < 武将能力_末; ++i)
		{
			max_stat[i] = f.readUInt8();
			init_stat[i] = f.readUInt8();
		}
		talent_status = f.readUInt8();
		remained_time = f.readUInt8();
		time_extended = f.readBool();
		is_out = f.readBool();
		train_event = f.readUInt32();
		for (int i = 0; i < 3; ++i)
			recent_special_event[i] = f.readUInt8();
		teaching_method = f.readUInt8();
		out_time = f.readInt8();
		talent_event_happened = f.readBool();
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_势力 - (after_pos - pre_pos));//f.movePos(预留字节_势力 - (after_pos - pre_pos));
	}
}

class specialinfo : EXdata
{
	int spec_id;
	int16 person;//将军
	int16 building_id;
	int gold;
	int food;
	int troops;
	int population;

	int gold_inc;
	int food_inc;
	int troops_inc;
	int population_inc;

	uint spec_set_;
	array<bool> spec_set(32, false);//0 是否允许运输---弃用

	//初始化
	specialinfo(int id) override
	{
	}
	//因为没有需要id，所以如果写下面这种，会导致前面的被冲掉，所以就不用提供下面这张声明方式了
	//下面这种写法用于定义全局变量，先声明，然后用get_info获取信息后使用
	specialinfo() override {}

	void init() override
	{
		person = -1;
		building_id = -1;
		gold = 0;
		food = 0;
		troops = 0;
		population = 0;

		gold_inc = 0;
		food_inc = 0;
		troops_inc = 0;
		population_inc = 0;

		spec_set_ = 0;
		array<bool> temp(32, false);
		spec_set = temp;//0 是否允许运输
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		int pre_pos = f.getPos();
		f.writeInt16(person);
		f.writeInt16(building_id);
		f.writeInt32(gold);
		f.writeInt32(food);
		f.writeInt32(troops);
		f.writeInt32(population);
		f.writeInt32(gold_inc);
		f.writeInt32(food_inc);
		f.writeInt32(troops_inc);
		f.writeInt32(population_inc);
		f.writeUInt32(spec_set_);
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_地名 - (after_pos - pre_pos));//f.movePos(预留字节_地名 - (after_pos - pre_pos));
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		spec_id = id;
		int pre_pos = f.getPos();
		person = f.readInt16();
		building_id = f.readInt16();
		gold = f.readInt32();
		food = f.readInt32();
		troops = f.readInt32();
		population = f.readInt32();
		gold_inc = f.readInt32();
		food_inc = f.readInt32();
		troops_inc = f.readInt32();
		population_inc = f.readInt32();
		spec_set_ = f.readUInt32();
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_地名 - (after_pos - pre_pos));//f.movePos(预留字节_地名 - (after_pos - pre_pos));
	}

	//相关支持函数
	void set_spec_set(uint pos, bool value)
	{
		spec_set_ = ch::set_bit(spec_set_, pos, value);//因为函数的数值不传出，所以需要赋值
	}

	bool get_spec_set(uint pos)
	{
		return ch::test_bit(spec_set_, pos);
	}

	int get_max_gold()
	{
		int max = get_spec_set(SPEC_MAX_INC) ? 100000 : 30000;
		return max;
	}

	int get_max_food()
	{
		int max = get_spec_set(SPEC_MAX_INC) ? 300000 : 60000;
		return max;
	}

	int get_max_troops()
	{
		int max = get_spec_set(SPEC_MAX_INC) ? 80000 : 30000;
		return max;
	}

	int get_max_population()
	{
		int max = 300000;
		return max;
	}

	int add_troops(int value)
	{
		int max_troops = get_max_troops();
		int after_troops = 0;
		if (troops + value > 0)
		{
			after_troops = max_troops;
			if (troops + value < max_troops)
			{
				after_troops = troops + value;
			}
		}
		int dif = after_troops - troops;
		set_troops(after_troops);//设置兵力
		return dif;
	}

	void set_troops(int value)
	{
		int max_troops = get_max_troops();
		if (value < 0)
			value = 0;
		troops = pk::min(max_troops, value);
	}

	int add_gold(int value)
	{
		int max_gold = get_max_gold();
		int after_gold = 0;
		if (gold + value > 0)
		{
			after_gold = max_gold;
			if (gold + value < max_gold)
			{
				after_gold = gold + value;
			}
		}
		int dif = after_gold - gold;
		set_gold(after_gold);//设置兵力
		return dif;
	}

	void set_gold(int value)
	{
		int max_gold = get_max_gold();
		if (value < 0)
			value = 0;
		gold = pk::min(max_gold, value);
	}

	int add_food(int value)
	{
		int max_food = get_max_food();
		int after_food = 0;
		if (food + value > 0)
		{
			after_food = max_food;
			if (food + value < max_food)
			{
				after_food = food + value;
			}
		}
		int dif = after_food - food;
		set_food(after_food);//设置兵力
		return dif;
	}

	void set_food(int value)
	{
		int max_food = get_max_food();
		if (value < 0)
			value = 0;
		food = pk::min(max_food, value);
	}

	int add_population(int value)
	{
		int max_population = get_max_population();
		int after_population = 0;
		if (population + value > 0)
		{
			after_population = max_population;
			if (population + value < max_population)
			{
				after_population = population + value;
			}
		}
		int dif = after_population - population;
		set_population(after_population);//设置兵力
		return dif;
	}

	void set_population(int value)
	{
		int max_population = get_max_population();
		if (value < 0)
			value = 0;
		population = pk::min(max_population, value);
	}

}

class settinginfo : EXdata
{
	int setting_id;
	//剧情已发生和剧情对xx势力已发生
	array<uint32> province_deserter(12, 0);
	array<bool> eve_happened(128, false);//就开关做成数组，需记录日期的额外做吧，一个日期需要1个int32太占地方了
	array<uint32> eve_happened_(4, 0);

	uint8 rumor_timer;

	uint16 sangu_1_turn_count;//触发三顾1时经过的旬数
	uint16 sangu_2_turn_count;//触发三顾2时经过的旬数
	//最多同时存在4个联盟好了
	array<int8> alliance_target_id(4, -1);
	array<int8> alliance_leader_id(4, -1);
	array<array<int8>> alliance_target_base(4, array<int8>(6, -1));//存联盟攻击目标的数组
	array<array<int8>> alliance_member_id(4, array<int8>(5, -1));//存组建中联盟成员的数组，无需存目标势力
	array<int8> alliance_remain_time(4, -1);//联军剩余时间

	array<uint16> ambush_person_id(3, uint16(-1));
	uint16 ambush_troops = uint16(-1);//兵力最大不超过6w,足够存
	uint16 ambush_food = uint16(-1);//非运输队食物最大不超过5w,足够存
	uint16 ambush_gold = uint16(-1);//非运输队食物最大不超过1w,足够存
	bool ambush_triggered = false;
	bool hex_ambush_triggered = false;


	array<bool> mod_set(32, false);//迷雾开关放17
	uint32 mod_set_;
	uint8 spec_strength = 255;


	array<uint16> bandit_times(5, 0); // 异族冷却期

	//初始化
	settinginfo(int id) override
	{
	}
	//因为没有需要id，所以如果写下面这种，会导致前面的被冲掉，所以就不用提供下面这张声明方式了
	//下面这种写法用于定义全局变量，先声明，然后用get_info获取信息后使用
	settinginfo() override {}

	void init() override
	{

		province_deserter = { 0,0,0,0,0,0,0,0,0,0,0,0 };//州流民

		array<bool> temp0(128, false);
		eve_happened = temp0;
		for (int i = 0; i < 4; ++i)
			eve_happened_[i] = 0;

		rumor_timer = 0;
		sangu_1_turn_count = 0;
		sangu_2_turn_count = 0;

		alliance_target_id = { -1, -1, -1, -1 };
		alliance_leader_id = { -1, -1, -1, -1 };
		//array<array<uint8>> alliance_target_base(4, array<uint8>(6, 255));//存联盟攻击目标的数组
		array<array<int8>> temp1(4, array<int8>(5, -1));
		alliance_member_id = temp1;//存组建中联盟成员的数组，无需存目标势力
		alliance_remain_time = { -1, -1, -1, -1 };

		//mod设定不应该在剧本初始化时重置，因为这是游戏开始时设置的
		//array<bool> temp2(32, false);
		//mod_set = temp2;
		spec_strength = 0;

		bandit_times = { 0, 0, 0, 0, 0 };
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		set_mod_set(视野迷雾系统_开关, pk::get_fog_state());//迷雾在core2内部，需特殊处理来同步
		int pre_pos = f.getPos();
		for (int i = 0; i < 州_末; ++i)
			f.writeUInt32(province_deserter[i]);

		for (int i = 0; i < 4; ++i)
			f.writeUInt32(eve_happened_[i]);
		f.writeUInt8(rumor_timer);
		f.writeUInt16(sangu_1_turn_count);
		f.writeUInt16(sangu_2_turn_count);
		for (int i = 0; i < 4; ++i)
		{
			f.writeInt8(alliance_target_id[i]);
			f.writeInt8(alliance_leader_id[i]);
			for (int j = 0; j < 6; ++j)
				f.writeInt8(alliance_target_base[i][j]);
			for (int j = 0; j < 5; ++j)
				f.writeInt8(alliance_member_id[i][j]);
			f.writeInt8(alliance_remain_time[i]);
		}
		for (int i = 0; i < 3; ++i)
			f.writeUInt16(ambush_person_id[i]);
		f.writeUInt16(ambush_troops);
		f.writeUInt16(ambush_food);
		f.writeUInt16(ambush_gold);
		f.writeBool(ambush_triggered);
		f.writeBool(hex_ambush_triggered);
		f.writeUInt32(mod_set_);
		f.writeUInt8(spec_strength);
		for (int i = 0; i < 5; ++i)
			f.writeUInt16(bandit_times[i]);
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_设定 - (after_pos - pre_pos));//f.movePos(预留字节_设定 - (after_pos - pre_pos));
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		setting_id = id;
		int pre_pos = f.getPos();
		for (int i = 0; i < 州_末; ++i)
			province_deserter[i] = f.readUInt32();
		for (int i = 0; i < 4; ++i)
			eve_happened_[i] = f.readUInt32();
		rumor_timer = f.readUInt8();
		sangu_1_turn_count = f.readUInt16();
		sangu_2_turn_count = f.readUInt16();
		for (int i = 0; i < 4; ++i)
		{
			alliance_target_id[i] = f.readInt8();
			alliance_leader_id[i] = f.readInt8();
			for (int j = 0; j < 6; ++j)
				alliance_target_base[i][j] = f.readInt8();
			for (int j = 0; j < 5; ++j)
				alliance_member_id[i][j] = f.readInt8();
			alliance_remain_time[i] = f.readInt8();
		}
		for (int i = 0; i < 3; ++i)
			ambush_person_id[i] = f.readUInt16();
		ambush_troops = f.readUInt16();
		ambush_food = f.readUInt16();
		ambush_gold = f.readUInt16();
		ambush_triggered = f.readBool();
		hex_ambush_triggered = f.readBool();
		mod_set_ = f.readUInt32();
		spec_strength = f.readUInt8();
		for (int i = 0; i < 5; ++i)
			bandit_times[i] = f.readUInt16();
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_设定 - (after_pos - pre_pos));//f.movePos(预留字节_设定 - (after_pos - pre_pos));

		pk::set_fog_state(get_mod_set(视野迷雾系统_开关), false);//迷雾在core2内部，需特殊处理来同步
	}

	void set_onebase_survive(bool value)
	{
		mod_set_ = ch::set_bit(mod_set_, 单港关存活_开关, value);//mod_set[单港关存活_开关] = value;
		pk::set_onebase_survive(value);
	}

	bool get_onebase_survive()
	{
		bool value = pk::get_onebase_survive();
		//mod_set[单港关存活_开关] = value;//确保状态一致
		return value;
	}

	void set_eve_happened(uint pos, bool value)
	{
		eve_happened_[pos / 32] = ch::set_bit(eve_happened_[pos / 32], pos % 32, value);//因为函数的数值不传出，所以需要赋值
	}

	bool get_eve_happened(uint pos)
	{
		return ch::test_bit(eve_happened_[pos / 32], pos % 32);
	}

	void set_mod_set(int pos, bool value)
	{
		//mod_set_ = ch::set_bit(mod_set_, pos, value);//因为函数的数值不传出，所以需要赋值
		//pk::trace(pk::format("set_mod_set before:mod_set_:{:b},", mod_set_));
		mod_set_ = pk::set_bit(mod_set_, pos, value);
		//pk::trace(pk::format("set_mod_set:mod_set_:{:b},pos:{},value:{},after_v:{}", mod_set_, pos, value, get_mod_set(pos)));
	}

	bool get_mod_set(int pos)
	{
		return pk::test_bit(mod_set_, pos);
	}

	void add_alliance_member(int alliance_id, int force_id)
	{
		if (alliance_id < 0 or alliance_id > 3) return;
		if (!pk::is_valid_normal_force_id(force_id)) return;

		for (int i = 0; i < 5; ++i)
		{
			if (!pk::is_valid_normal_force_id(alliance_member_id[alliance_id][i]))
			{
				alliance_member_id[alliance_id][i] = force_id;
				break;
			}

		}
	}
}

class autoarmyinfo : EXdata
{
	int autoarmy_id;
	//int16 member1;
	//int16 member2;
	//int16 member3;
	array<int16> member(3, -1);
	int8 ground_weapon = 0;
	int8 sea_weapon = 9;
	int16 freq = 0;

	//初始化
	autoarmyinfo(int id) override
	{
		get_info(id);
	}
	//因为没有需要id，所以如果写下面这种，会导致前面的被冲掉，所以就不用提供下面这张声明方式了
	//下面这种写法用于定义全局变量，先声明，然后用get_info获取信息后使用
	autoarmyinfo() override {}

	void init() override
	{
		member = { -1,-1,-1 };
		ground_weapon = 0;
		sea_weapon = 9;
		freq = 0;
	}

	void serialize(pk::s11writer@ f, int id = -1) override
	{
		int pre_pos = f.getPos();
		for (int i = 0; i < 3; ++i)
			f.writeInt16(member[i]);
		f.writeInt8(ground_weapon);
		f.writeInt8(sea_weapon);
		f.writeInt16(freq);
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_组队 - (after_pos - pre_pos));//f.movePos(预留字节_组队 - (after_pos - pre_pos));
	}

	void deserialize(pk::s11reader@ f, int id = -1) override
	{
		autoarmy_id = id;
		int pre_pos = f.getPos();
		for (int i = 0; i < 3; ++i)
			member[i] = f.readInt16();
		ground_weapon = f.readInt8();
		sea_weapon = f.readInt8();
		freq = f.readInt16();
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_组队 - (after_pos - pre_pos));//f.movePos(预留字节_组队 - (after_pos - pre_pos));
	}

	void serialize(file@ f, int id = -1) override
	{
		int pre_pos = f.getPos();
		for (int i = 0; i < 3; ++i)
			f.writeInt16(member[i]);
		f.writeInt8(ground_weapon);
		f.writeInt8(sea_weapon);
		f.writeInt16(freq);
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::write_multibyte(f, 预留字节_组队 - (after_pos - pre_pos));//f.movePos(预留字节_组队 - (after_pos - pre_pos));
	}

	void deserialize(file@ f, int id = -1) override
	{
		autoarmy_id = id;
		int pre_pos = f.getPos();
		for (int i = 0; i < 3; ++i)
			member[i] = f.readInt16();
		ground_weapon = f.readInt8();
		sea_weapon = f.readInt8();
		freq = f.readInt16();
		int after_pos = f.getPos();
		//占位,加入数据后，此处需减去对应字节数
		ch::read_multibyte(f, 预留字节_组队 - (after_pos - pre_pos));//f.movePos(预留字节_组队 - (after_pos - pre_pos));
	}

	int get_value(int prop_id)
	{
		switch (prop_id)
		{
			case 自动组队_主将:
				return member[0];
			case 自动组队_副将1:
				return member[1];
			case 自动组队_副将2:
				return member[2];
			case 自动组队_陆上兵器:
				return ground_weapon;
			case 自动组队_水上兵器:
				return sea_weapon;
			case 自动组队_频率:
				return freq;
			default:
				break;
		}
		return -1;
	}

	string get_string(int prop_id)
	{
		switch (prop_id)
		{
			case 自动组队_主将:
			case 自动组队_副将1:
			case 自动组队_副将2:
				return ch::get_person_name(pk::get_person(get_value(prop_id)));
			case 自动组队_陆上兵器:
			case 自动组队_水上兵器:
				return ch::get_weapon_name(get_value(prop_id));
			case 自动组队_频率:
				return pk::format("{}", freq);
			default:
				break;
		}
		return "";
	}

}

//这个放全局
class unit_order_info
{
	int id;
	int order;
	pk::point pos;
	int score;
	int target ;

	unit_order_info()
	{
		init();
	}
	void init()
	{
		id = -1;
		order = -1;
		pos = pk::point(-1, -1);
		score = -1;
		target =-1;
	}


};
//
////723的函数
//unit_order_info get_xxx_unit_order_info(pk::unit@ unit)
//{
//	unit_order_info info;
//	info.order = 1;
//	info.pos = pk::point(1,1);
//	info.score = 1000;
//	return unit_order_info;
//}
////724的函数
//unit_order_info get_yyy_unit_order_info(pk::unit@ unit)
//{
//	unit_order_info info;
//	info.order = 1;
//	info.pos = pk::point(1, 1);
//	info.score = 1000;
//	return unit_order_info;
//}
//
////266里的函数
//
//array<unit_order_info> unit_order_info_arr;
//
//void get_all_unit_order_info(pk::unit@ unit)
//{
//	unit_order_info_arr.insertLast(get_xxx_unit_order_info(unit));
//	unit_order_info_arr.insertLast(get_yyy_unit_order_info(unit));
//}

class base_rank_info
{
	int score_rank;
	int in_line_level_rank;
	int in_line_score_rank;
	int statue_rank;
	int marchable_troops_rank;
	int retained_troops_rank;
	int around_self_troops_rank;
	int around_enemy_troops_rank;
	int in_range_enemy_troops_rank;
	int in_range_enemy_troops_from_player_rank;
	int max_effective_troops_rank;
	int atk_power_rank;
	int def_power_rank;
	int attacked_troops_rank;
	int attacking_troops_rank;

	int real_person_rank;
	int want_person_rank;
	int real_person_for_district_rank;
	int want_person_for_district_rank;
};

array <base_rank_info> Rank_info(据点_末);

class base_ai_info
{
	int base_id;
	int score; // 据点分(用于分配资源)
	int in_line_level; // 据点距离前线最小距离(前线层级)
	int in_line_score; // 据点运输分(用于运输计算)
	int statue; // 据点运输分(用于运输计算)
	int marchable_troops; // 据点和周遭总兵力
	int retained_troops; // 据点态势分析:支援城市自身留存兵力
	int around_self_troops; // 据点态势分析:据点周围友军兵力
	int around_enemy_troops; // 据点态势分析:据点周围敌方兵力
	int in_range_enemy_troops; // 据点态势分析:据点所属范围内敌方兵力
	int in_range_enemy_troops_from_player; // 据点态势分析:据点所属范围内敌方兵力(来自玩家)
	int max_effective_troops; // 据点态势分析:据点实际可用兵力
	int atk_power; // 据点态势分析:据点进攻能力
	int def_power; // 据点态势分析:据点防御能力
	int attacked_troops; // 据点态势分析:正在攻击据点的部队
	int attacking_troops; // 据点态势分析:据点出征的部队

	int real_person; // 据点态势分析:城市实际武将数
	int want_person; // 据点态势分析:城市合意武将数
	int real_person_for_district; // 军团计算
	int want_person_for_district; // 军团计算
};

array<base_ai_info> base_ai_info_arr(据点_末);

void get_rank()
{
	base_ai_info_arr.sort(function(a, b) { return a.score > b.score; });

	for (int i = 0; i < 据点_末; ++i)
	{
		Rank_info[base_ai_info_arr[i].base_id].score_rank = i;//此时i不是据点id，而是顺序
	}

	base_ai_info_arr.sort(function(a, b){return a.in_line_level > b.in_line_level;});

	for (int i = 0; i < 据点_末; ++i)
	{
		Rank_info[base_ai_info_arr[i].base_id].in_line_level_rank = i;//此时i不是据点id，而是顺序
	}

	//下方依次排序就好
}


